Skip to content

Commit

Permalink
Fix jsx-closing-bracket-location for multiline props (fixes #199)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Aug 31, 2015
1 parent 4b54ac1 commit 546e893
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ module.exports = function(context) {
var tag = context.getFirstToken(node.name).loc.start;
var lastProp;
if (node.attributes.length) {
lastProp = context.getFirstToken(node.attributes[node.attributes.length - 1]).loc.start;
lastProp = node.attributes[node.attributes.length - 1];
lastProp = {
column: context.getFirstToken(lastProp).loc.start.column,
line: context.getLastToken(lastProp).loc.end.line
};
}
return {
tag: tag,
Expand Down
29 changes: 29 additions & 0 deletions tests/lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,35 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
].join('\n'),
options: [{location: 'props-aligned'}],
ecmaFeatures: {jsx: true}
}, {
code: [
'<App',
' foo={function() {',
' console.log(\'bar\');',
' }} />'
].join('\n'),
options: [{location: 'after-props'}],
ecmaFeatures: {jsx: true}
}, {
code: [
'<App',
' foo={function() {',
' console.log(\'bar\');',
' }}',
' />'
].join('\n'),
options: [{location: 'props-aligned'}],
ecmaFeatures: {jsx: true}
}, {
code: [
'<App',
' foo={function() {',
' console.log(\'bar\');',
' }}',
'/>'
].join('\n'),
options: [{location: 'tag-aligned'}],
ecmaFeatures: {jsx: true}
}],

invalid: [{
Expand Down

0 comments on commit 546e893

Please sign in to comment.