Skip to content

Commit

Permalink
[Fix] jsx-indent: Fix indent handling for closing parentheses
Browse files Browse the repository at this point in the history
Fixes #618.
  • Loading branch information
stefanbuck authored and ljharb committed Dec 16, 2019
1 parent da7a045 commit bba0015
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
14 changes: 13 additions & 1 deletion lib/rules/jsx-indent.js
Expand Up @@ -395,7 +395,19 @@ module.exports = {
checkNodesIndent(node, parentNodeIndent + indentSize);
},
Literal: handleLiteral,
JSXText: handleLiteral
JSXText: handleLiteral,
ReturnStatement(node) {
if (!node.parent) {
return;
}

const openingIndent = getNodeIndent(node);
const closingIndent = getNodeIndent(node, true);

if (closingIndent !== openingIndent) {
report(node, openingIndent, closingIndent);
}
}
};
}
};
66 changes: 64 additions & 2 deletions tests/lib/rules/jsx-indent.js
Expand Up @@ -997,6 +997,26 @@ const Component = () => (
'const b = `b\nb`;',
'}'
].join('\n')
}, {
code: [
'function App() {',
' return (',
' <App />',
' );',
'}'
].join('\n'),
options: [2],
parserOptions
}, {
code: [
'function App() {',
' return <App>',
' <Foo />',
' </App>;',
'}'
].join('\n'),
options: [2],
parserOptions
}],

invalid: [{
Expand Down Expand Up @@ -1102,7 +1122,10 @@ const Component = () => (
'}'
].join('\n'),
options: [2],
errors: [{message: 'Expected indentation of 2 space characters but found 9.'}]
errors: [
{message: 'Expected indentation of 2 space characters but found 9.'},
{message: 'Expected indentation of 2 space characters but found 9.'}
]
}, {
code: [
'function App() {',
Expand All @@ -1119,7 +1142,10 @@ const Component = () => (
'}'
].join('\n'),
options: [2],
errors: [{message: 'Expected indentation of 2 space characters but found 4.'}]
errors: [
{message: 'Expected indentation of 2 space characters but found 4.'},
{message: 'Expected indentation of 2 space characters but found 4.'}
]
}, {
code: [
'function App() {',
Expand Down Expand Up @@ -2026,5 +2052,41 @@ const Component = () => (
errors: [
{message: 'Expected indentation of 4 space characters but found 0.'}
]
}, {
code: [
'function App() {',
' return (',
' <App />',
' );',
'}'
].join('\n'),
output: [
'function App() {',
' return (',
' <App />',
' );',
'}'
].join('\n'),
options: [2],
parserOptions,
errors: [{message: 'Expected indentation of 2 space characters but found 4.'}]
}, {
code: [
'function App() {',
' return (',
' <App />',
');',
'}'
].join('\n'),
output: [
'function App() {',
' return (',
' <App />',
' );',
'}'
].join('\n'),
options: [2],
parserOptions,
errors: [{message: 'Expected indentation of 2 space characters but found 0.'}]
}]
});

0 comments on commit bba0015

Please sign in to comment.