Skip to content

Commit

Permalink
Fix --fix for props-aligned in jsx-closing-bracket-location
Browse files Browse the repository at this point in the history
  • Loading branch information
pfhayes authored and yannickcr committed Jul 18, 2016
1 parent 78a4a9e commit cbb5930
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 9 deletions.
11 changes: 2 additions & 9 deletions lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ module.exports = function(context) {
'JSXOpeningElement:exit': function(node) {
var attributeNode = lastAttributeNode[getOpeningElementId(node)];
var cachedLastAttributeEndPos = attributeNode ? attributeNode.end : null;
var cachedLastAttributeStartPos = attributeNode ? attributeNode.start : null;
var expectedNextLine;
var tokens = getTokensLocations(node);
var expectedLocation = getExpectedLocation(tokens);
Expand Down Expand Up @@ -205,17 +204,11 @@ module.exports = function(context) {
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end],
(expectedNextLine ? '\n' : '') + closingTag);
case 'props-aligned':
var spaces = new Array(cachedLastAttributeEndPos - cachedLastAttributeStartPos);
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end],
'\n' + spaces.join(' ') + closingTag);
case 'tag-aligned':
var tagSpaces = new Array(+correctColumn + 1);
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end],
'\n' + tagSpaces.join(' ') + closingTag);
case 'line-aligned':
var lineSpaces = new Array(+correctColumn + 1);
var spaces = new Array(+correctColumn + 1);
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end],
'\n' + lineSpaces.join(' ') + closingTag);
'\n' + spaces.join(' ') + closingTag);
default:
return true;
}
Expand Down
96 changes: 96 additions & 0 deletions tests/lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,102 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
line: 2,
column: 8
}]
}, {
code: [
'const Button = function(props) {',
' return (',
' <Button',
' size={size}',
' onClick={onClick}',
' >',
' Button Text',
' </Button>',
' );',
'};'
].join('\n'),
output: [
'const Button = function(props) {',
' return (',
' <Button',
' size={size}',
' onClick={onClick}',
' >',
' Button Text',
' </Button>',
' );',
'};'
].join('\n'),
options: ['props-aligned'],
parserOptions: parserOptions,
errors: [{
message: messageWithDetails(MESSAGE_PROPS_ALIGNED, 7, false),
line: 6,
column: 37
}]
}, {
code: [
'const Button = function(props) {',
' return (',
' <Button',
' size={size}',
' onClick={onClick}',
' >',
' Button Text',
' </Button>',
' );',
'};'
].join('\n'),
output: [
'const Button = function(props) {',
' return (',
' <Button',
' size={size}',
' onClick={onClick}',
' >',
' Button Text',
' </Button>',
' );',
'};'
].join('\n'),
options: ['tag-aligned'],
parserOptions: parserOptions,
errors: [{
message: messageWithDetails(MESSAGE_TAG_ALIGNED, 5, false),
line: 6,
column: 37
}]
}, {
code: [
'const Button = function(props) {',
' return (',
' <Button',
' size={size}',
' onClick={onClick}',
' >',
' Button Text',
' </Button>',
' );',
'};'
].join('\n'),
output: [
'const Button = function(props) {',
' return (',
' <Button',
' size={size}',
' onClick={onClick}',
' >',
' Button Text',
' </Button>',
' );',
'};'
].join('\n'),
options: ['line-aligned'],
parserOptions: parserOptions,
errors: [{
message: messageWithDetails(MESSAGE_LINE_ALIGNED, 5, false),
line: 6,
column: 37
}]
}, {
code: [
'<Provider',
Expand Down

0 comments on commit cbb5930

Please sign in to comment.