Skip to content

Commit

Permalink
[Fix]jsx-indent: don't check literals not within JSX
Browse files Browse the repository at this point in the history
  • Loading branch information
toshi-toma committed Feb 3, 2020
1 parent 37c4ef3 commit 2be9f24
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rules/jsx-indent.js
Expand Up @@ -374,6 +374,9 @@ module.exports = {
if (!node.parent) {
return;
}
if (node.parent.type !== 'JSXElement' && node.parent.type !== 'JSXFragment') {
return;
}
const parentNodeIndent = getNodeIndent(node.parent);
checkLiteralNodeIndent(node, parentNodeIndent + indentSize);
}
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/rules/jsx-indent.js
Expand Up @@ -989,6 +989,14 @@ const Component = () => (
'</App>'
].join('\n'),
options: ['tab']
}, {
// don't check literals not within JSX. See #2563
code: [
'function foo() {',
'const a = `aa`;',
'const b = `b\nb`;',
'}'
].join('\n')
}],

invalid: [{
Expand Down Expand Up @@ -2003,5 +2011,20 @@ const Component = () => (
errors: [
{message: 'Expected indentation of 1 tab character but found 2.'}
]
}, {
code: [
'<>',
'aaa',
'</>'
].join('\n'),
parser: parsers.BABEL_ESLINT,
output: [
'<>',
' aaa',
'</>'
].join('\n'),
errors: [
{message: 'Expected indentation of 4 space characters but found 0.'}
]
}]
});

0 comments on commit 2be9f24

Please sign in to comment.