Skip to content

Commit cbb5930

Browse files
pfhayesyannickcr
authored andcommitted
Fix --fix for props-aligned in jsx-closing-bracket-location
1 parent 78a4a9e commit cbb5930

File tree

2 files changed

+98
-9
lines changed

2 files changed

+98
-9
lines changed

lib/rules/jsx-closing-bracket-location.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ module.exports = function(context) {
167167
'JSXOpeningElement:exit': function(node) {
168168
var attributeNode = lastAttributeNode[getOpeningElementId(node)];
169169
var cachedLastAttributeEndPos = attributeNode ? attributeNode.end : null;
170-
var cachedLastAttributeStartPos = attributeNode ? attributeNode.start : null;
171170
var expectedNextLine;
172171
var tokens = getTokensLocations(node);
173172
var expectedLocation = getExpectedLocation(tokens);
@@ -205,17 +204,11 @@ module.exports = function(context) {
205204
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end],
206205
(expectedNextLine ? '\n' : '') + closingTag);
207206
case 'props-aligned':
208-
var spaces = new Array(cachedLastAttributeEndPos - cachedLastAttributeStartPos);
209-
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end],
210-
'\n' + spaces.join(' ') + closingTag);
211207
case 'tag-aligned':
212-
var tagSpaces = new Array(+correctColumn + 1);
213-
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end],
214-
'\n' + tagSpaces.join(' ') + closingTag);
215208
case 'line-aligned':
216-
var lineSpaces = new Array(+correctColumn + 1);
209+
var spaces = new Array(+correctColumn + 1);
217210
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end],
218-
'\n' + lineSpaces.join(' ') + closingTag);
211+
'\n' + spaces.join(' ') + closingTag);
219212
default:
220213
return true;
221214
}

tests/lib/rules/jsx-closing-bracket-location.js

+96
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,102 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
651651
line: 2,
652652
column: 8
653653
}]
654+
}, {
655+
code: [
656+
'const Button = function(props) {',
657+
' return (',
658+
' <Button',
659+
' size={size}',
660+
' onClick={onClick}',
661+
' >',
662+
' Button Text',
663+
' </Button>',
664+
' );',
665+
'};'
666+
].join('\n'),
667+
output: [
668+
'const Button = function(props) {',
669+
' return (',
670+
' <Button',
671+
' size={size}',
672+
' onClick={onClick}',
673+
' >',
674+
' Button Text',
675+
' </Button>',
676+
' );',
677+
'};'
678+
].join('\n'),
679+
options: ['props-aligned'],
680+
parserOptions: parserOptions,
681+
errors: [{
682+
message: messageWithDetails(MESSAGE_PROPS_ALIGNED, 7, false),
683+
line: 6,
684+
column: 37
685+
}]
686+
}, {
687+
code: [
688+
'const Button = function(props) {',
689+
' return (',
690+
' <Button',
691+
' size={size}',
692+
' onClick={onClick}',
693+
' >',
694+
' Button Text',
695+
' </Button>',
696+
' );',
697+
'};'
698+
].join('\n'),
699+
output: [
700+
'const Button = function(props) {',
701+
' return (',
702+
' <Button',
703+
' size={size}',
704+
' onClick={onClick}',
705+
' >',
706+
' Button Text',
707+
' </Button>',
708+
' );',
709+
'};'
710+
].join('\n'),
711+
options: ['tag-aligned'],
712+
parserOptions: parserOptions,
713+
errors: [{
714+
message: messageWithDetails(MESSAGE_TAG_ALIGNED, 5, false),
715+
line: 6,
716+
column: 37
717+
}]
718+
}, {
719+
code: [
720+
'const Button = function(props) {',
721+
' return (',
722+
' <Button',
723+
' size={size}',
724+
' onClick={onClick}',
725+
' >',
726+
' Button Text',
727+
' </Button>',
728+
' );',
729+
'};'
730+
].join('\n'),
731+
output: [
732+
'const Button = function(props) {',
733+
' return (',
734+
' <Button',
735+
' size={size}',
736+
' onClick={onClick}',
737+
' >',
738+
' Button Text',
739+
' </Button>',
740+
' );',
741+
'};'
742+
].join('\n'),
743+
options: ['line-aligned'],
744+
parserOptions: parserOptions,
745+
errors: [{
746+
message: messageWithDetails(MESSAGE_LINE_ALIGNED, 5, false),
747+
line: 6,
748+
column: 37
749+
}]
654750
}, {
655751
code: [
656752
'<Provider',

0 commit comments

Comments
 (0)