Skip to content

Commit 8b576be

Browse files
toshi-tomaljharb
authored andcommitted
[Fix] jsx-indent: don't check literals not within JSX
Fixes #2563
1 parent 37c4ef3 commit 8b576be

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/rules/jsx-indent.js

+3
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ module.exports = {
374374
if (!node.parent) {
375375
return;
376376
}
377+
if (node.parent.type !== 'JSXElement' && node.parent.type !== 'JSXFragment') {
378+
return;
379+
}
377380
const parentNodeIndent = getNodeIndent(node.parent);
378381
checkLiteralNodeIndent(node, parentNodeIndent + indentSize);
379382
}

tests/lib/rules/jsx-indent.js

+23
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,14 @@ const Component = () => (
989989
'</App>'
990990
].join('\n'),
991991
options: ['tab']
992+
}, {
993+
// don't check literals not within JSX. See #2563
994+
code: [
995+
'function foo() {',
996+
'const a = `aa`;',
997+
'const b = `b\nb`;',
998+
'}'
999+
].join('\n')
9921000
}],
9931001

9941002
invalid: [{
@@ -2003,5 +2011,20 @@ const Component = () => (
20032011
errors: [
20042012
{message: 'Expected indentation of 1 tab character but found 2.'}
20052013
]
2014+
}, {
2015+
code: [
2016+
'<>',
2017+
'aaa',
2018+
'</>'
2019+
].join('\n'),
2020+
parser: parsers.BABEL_ESLINT,
2021+
output: [
2022+
'<>',
2023+
' aaa',
2024+
'</>'
2025+
].join('\n'),
2026+
errors: [
2027+
{message: 'Expected indentation of 4 space characters but found 0.'}
2028+
]
20062029
}]
20072030
});

0 commit comments

Comments
 (0)