Skip to content

Commit e2f72f1

Browse files
committed
Fix jsx-closing-bracket-location for multi-line prop (fixes #889)
1 parent a1b8d45 commit e2f72f1

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module.exports = {
9595
if (typeof tokens.lastProp === 'undefined') {
9696
location = 'after-tag';
9797
// Is always after the last prop if this one is on the same line as the opening bracket
98-
} else if (tokens.opening.line === tokens.lastProp.firstLine) {
98+
} else if (tokens.opening.line === tokens.lastProp.lastLine) {
9999
location = 'after-props';
100100
// Else use configuration dependent on selfClosing property
101101
} else {

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

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,24 +197,27 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
197197
}, {
198198
code: [
199199
'<App foo={function() {',
200-
' console.log(\'bar\');',
201-
'}}/>'
200+
' console.log(\'bar\');',
201+
' }}',
202+
' />'
202203
].join('\n'),
203204
options: [{location: 'props-aligned'}],
204205
parserOptions: parserOptions
205206
}, {
206207
code: [
207208
'<App foo={function() {',
208209
' console.log(\'bar\');',
209-
'}}/>'
210+
'}}',
211+
'/>'
210212
].join('\n'),
211213
options: [{location: 'tag-aligned'}],
212214
parserOptions: parserOptions
213215
}, {
214216
code: [
215217
'<App foo={function() {',
216218
' console.log(\'bar\');',
217-
'}}/>'
219+
'}}',
220+
'/>'
218221
].join('\n'),
219222
options: [{location: 'line-aligned'}],
220223
parserOptions: parserOptions
@@ -383,6 +386,18 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
383386
selfClosing: false
384387
}],
385388
parserOptions: parserOptions
389+
}, {
390+
code: [
391+
'<div className={[',
392+
' "some",',
393+
' "stuff",',
394+
' 2 ]}',
395+
'>',
396+
' Some text',
397+
'</div>'
398+
].join('\n'),
399+
options: [{location: 'tag-aligned'}],
400+
parserOptions: parserOptions
386401
}],
387402

388403
invalid: [{
@@ -919,5 +934,30 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
919934
options: [{location: 'line-aligned'}],
920935
parserOptions: parserOptions,
921936
errors: [MESSAGE_AFTER_TAG]
937+
}, {
938+
code: [
939+
'<div className={[',
940+
' "some",',
941+
' "stuff",',
942+
' 2 ]}>',
943+
' Some text',
944+
'</div>'
945+
].join('\n'),
946+
output: [
947+
'<div className={[',
948+
' "some",',
949+
' "stuff",',
950+
' 2 ]}',
951+
'>',
952+
' Some text',
953+
'</div>'
954+
].join('\n'),
955+
options: [{location: 'tag-aligned'}],
956+
parserOptions: parserOptions,
957+
errors: [{
958+
message: messageWithDetails(MESSAGE_TAG_ALIGNED, 1, true),
959+
line: 4,
960+
column: 7
961+
}]
922962
}]
923963
});

0 commit comments

Comments
 (0)