Skip to content

Commit 546e893

Browse files
committed
Fix jsx-closing-bracket-location for multiline props (fixes #199)
1 parent 4b54ac1 commit 546e893

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ module.exports = function(context) {
6969
var tag = context.getFirstToken(node.name).loc.start;
7070
var lastProp;
7171
if (node.attributes.length) {
72-
lastProp = context.getFirstToken(node.attributes[node.attributes.length - 1]).loc.start;
72+
lastProp = node.attributes[node.attributes.length - 1];
73+
lastProp = {
74+
column: context.getFirstToken(lastProp).loc.start.column,
75+
line: context.getLastToken(lastProp).loc.end.line
76+
};
7377
}
7478
return {
7579
tag: tag,

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,35 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
8888
].join('\n'),
8989
options: [{location: 'props-aligned'}],
9090
ecmaFeatures: {jsx: true}
91+
}, {
92+
code: [
93+
'<App',
94+
' foo={function() {',
95+
' console.log(\'bar\');',
96+
' }} />'
97+
].join('\n'),
98+
options: [{location: 'after-props'}],
99+
ecmaFeatures: {jsx: true}
100+
}, {
101+
code: [
102+
'<App',
103+
' foo={function() {',
104+
' console.log(\'bar\');',
105+
' }}',
106+
' />'
107+
].join('\n'),
108+
options: [{location: 'props-aligned'}],
109+
ecmaFeatures: {jsx: true}
110+
}, {
111+
code: [
112+
'<App',
113+
' foo={function() {',
114+
' console.log(\'bar\');',
115+
' }}',
116+
'/>'
117+
].join('\n'),
118+
options: [{location: 'tag-aligned'}],
119+
ecmaFeatures: {jsx: true}
91120
}],
92121

93122
invalid: [{

0 commit comments

Comments
 (0)