Skip to content

Commit d0dfc07

Browse files
committed
Fix jsx-indent for arrays (fixes #897, fixes #898)
1 parent 608c14a commit d0dfc07

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/rules/jsx-indent.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ module.exports = {
219219
if (!prevToken) {
220220
return;
221221
}
222-
if (prevToken.type === 'JSXText') {
222+
// Use the parent in a list or an array
223+
if (prevToken.type === 'JSXText' || prevToken.type === 'Punctuator' && prevToken.value === ',') {
223224
prevToken = sourceCode.getNodeByRangeIndex(prevToken.start).parent;
224225
}
225226
var parentElementIndent = getNodeIndent(prevToken);

tests/lib/rules/jsx-indent.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ ruleTester.run('jsx-indent', rule, {
167167
].join('\n'),
168168
parserOptions: parserOptions,
169169
options: [2]
170+
}, {
171+
code: [
172+
'[',
173+
' <div />,',
174+
' <div />',
175+
']'
176+
].join('\n'),
177+
parserOptions: parserOptions,
178+
options: [2]
170179
}],
171180

172181
invalid: [{
@@ -320,6 +329,24 @@ ruleTester.run('jsx-indent', rule, {
320329
errors: [
321330
{message: 'Expected indentation of 1 tab character but found 0.'}
322331
]
332+
}, {
333+
code: [
334+
'[',
335+
' <div />,',
336+
' <div />',
337+
']'
338+
].join('\n'),
339+
output: [
340+
'[',
341+
' <div />,',
342+
' <div />',
343+
']'
344+
].join('\n'),
345+
parserOptions: parserOptions,
346+
options: [2],
347+
errors: [
348+
{message: 'Expected indentation of 2 space characters but found 4.'}
349+
]
323350
}
324351
// Tests for future work. See the comment on line 42-43 in the rule near to fixable: 'whitespace' meta property,
325352
// Right now fixer function doesn't support replacing tabs with whitespaces and vice-versa.

0 commit comments

Comments
 (0)