Skip to content

Commit c650c75

Browse files
committed
Improved multiline prop support for jsx-closing-bracket-location
1 parent aba4f96 commit c650c75

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = function(context) {
5757
if (typeof tokens.lastProp === 'undefined') {
5858
location = 'after-tag';
5959
// Is always after the last prop if this one is on the same line as the opening bracket
60-
} else if (tokens.opening.line === tokens.lastProp.line) {
60+
} else if (tokens.opening.line === tokens.lastProp.firstLine) {
6161
location = 'after-props';
6262
// Else use configuration dependent on selfClosing property
6363
} else {
@@ -97,7 +97,7 @@ module.exports = function(context) {
9797
case 'after-tag':
9898
return tokens.tag.line === tokens.closing.line;
9999
case 'after-props':
100-
return tokens.lastProp.line === tokens.closing.line;
100+
return tokens.lastProp.lastLine === tokens.closing.line;
101101
case 'props-aligned':
102102
case 'tag-aligned':
103103
case 'line-aligned':
@@ -124,7 +124,8 @@ module.exports = function(context) {
124124
lastProp = node.attributes[node.attributes.length - 1];
125125
lastProp = {
126126
column: sourceCode.getFirstToken(lastProp).loc.start.column,
127-
line: sourceCode.getLastToken(lastProp).loc.end.line
127+
firstLine: sourceCode.getFirstToken(lastProp).loc.start.line,
128+
lastLine: sourceCode.getLastToken(lastProp).loc.end.line
128129
};
129130
}
130131
var openingLine = sourceCode.lines[opening.line - 1];
@@ -170,7 +171,7 @@ module.exports = function(context) {
170171

171172
if (correctColumn !== null) {
172173
expectedNextLine = tokens.lastProp &&
173-
(tokens.lastProp.line === tokens.closing.line);
174+
(tokens.lastProp.lastLine === tokens.closing.line);
174175
data.details = ' (expected column ' + (correctColumn + 1) +
175176
(expectedNextLine ? ' on the next line)' : ')');
176177
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,38 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
186186
].join('\n'),
187187
options: [{location: 'line-aligned'}],
188188
parserOptions: parserOptions
189+
}, {
190+
code: [
191+
'<App foo={function() {',
192+
' console.log(\'bar\');',
193+
'}}/>'
194+
].join('\n'),
195+
options: [{location: 'after-props'}],
196+
parserOptions: parserOptions
197+
}, {
198+
code: [
199+
'<App foo={function() {',
200+
' console.log(\'bar\');',
201+
'}}/>'
202+
].join('\n'),
203+
options: [{location: 'props-aligned'}],
204+
parserOptions: parserOptions
205+
}, {
206+
code: [
207+
'<App foo={function() {',
208+
' console.log(\'bar\');',
209+
'}}/>'
210+
].join('\n'),
211+
options: [{location: 'tag-aligned'}],
212+
parserOptions: parserOptions
213+
}, {
214+
code: [
215+
'<App foo={function() {',
216+
' console.log(\'bar\');',
217+
'}}/>'
218+
].join('\n'),
219+
options: [{location: 'line-aligned'}],
220+
parserOptions: parserOptions
189221
}, {
190222
code: [
191223
'<Provider store>',

0 commit comments

Comments
 (0)