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 7f87310 commit 088c5f6
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/rules/jsx-indent.js
Expand Up @@ -352,6 +352,18 @@ module.exports = {
}
const parentNodeIndent = getNodeIndent(node.parent);
checkNodesIndent(node, parentNodeIndent + indentSize);
},
ReturnStatement(node) {
if (!node.parent) {
return;
}

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

if (closingIndent !== openingIndent) {
report(node, openingIndent, closingIndent);
}
}
};
}
Expand Down
66 changes: 64 additions & 2 deletions tests/lib/rules/jsx-indent.js
Expand Up @@ -956,6 +956,26 @@ const Component = () => (
}
`,
options: [2, {indentLogicalExpressions: true}]
}, {
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 @@ -1038,7 +1058,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 @@ -1055,7 +1078,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 @@ -1883,5 +1909,41 @@ const Component = () => (
errors: [
{message: 'Expected indentation of 8 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 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 088c5f6

Please sign in to comment.