Skip to content

Commit

Permalink
Improve multiline prop support for jsx-closing-bracket-location
Browse files Browse the repository at this point in the history
  • Loading branch information
tuures authored and yannickcr committed Jun 5, 2016
1 parent 4353ddf commit 2a04fd4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = function(context) {
if (typeof tokens.lastProp === 'undefined') {
location = 'after-tag';
// Is always after the last prop if this one is on the same line as the opening bracket
} else if (tokens.opening.line === tokens.lastProp.line) {
} else if (tokens.opening.line === tokens.lastProp.firstLine) {
location = 'after-props';
// Else use configuration dependent on selfClosing property
} else {
Expand Down Expand Up @@ -97,7 +97,7 @@ module.exports = function(context) {
case 'after-tag':
return tokens.tag.line === tokens.closing.line;
case 'after-props':
return tokens.lastProp.line === tokens.closing.line;
return tokens.lastProp.lastLine === tokens.closing.line;
case 'props-aligned':
case 'tag-aligned':
case 'line-aligned':
Expand All @@ -124,7 +124,8 @@ module.exports = function(context) {
lastProp = node.attributes[node.attributes.length - 1];
lastProp = {
column: sourceCode.getFirstToken(lastProp).loc.start.column,
line: sourceCode.getLastToken(lastProp).loc.end.line
firstLine: sourceCode.getFirstToken(lastProp).loc.start.line,
lastLine: sourceCode.getLastToken(lastProp).loc.end.line
};
}
var openingLine = sourceCode.lines[opening.line - 1];
Expand Down Expand Up @@ -180,7 +181,7 @@ module.exports = function(context) {

if (correctColumn !== null) {
expectedNextLine = tokens.lastProp &&
(tokens.lastProp.line === tokens.closing.line);
(tokens.lastProp.lastLine === tokens.closing.line);
data.details = ' (expected column ' + (correctColumn + 1) +
(expectedNextLine ? ' on the next line)' : ')');
}
Expand Down
32 changes: 32 additions & 0 deletions tests/lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,38 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
].join('\n'),
options: [{location: 'line-aligned'}],
parserOptions: parserOptions
}, {
code: [
'<App foo={function() {',
' console.log(\'bar\');',
'}}/>'
].join('\n'),
options: [{location: 'after-props'}],
parserOptions: parserOptions
}, {
code: [
'<App foo={function() {',
' console.log(\'bar\');',
'}}/>'
].join('\n'),
options: [{location: 'props-aligned'}],
parserOptions: parserOptions
}, {
code: [
'<App foo={function() {',
' console.log(\'bar\');',
'}}/>'
].join('\n'),
options: [{location: 'tag-aligned'}],
parserOptions: parserOptions
}, {
code: [
'<App foo={function() {',
' console.log(\'bar\');',
'}}/>'
].join('\n'),
options: [{location: 'line-aligned'}],
parserOptions: parserOptions
}, {
code: [
'<Provider store>',
Expand Down

0 comments on commit 2a04fd4

Please sign in to comment.