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
Stefan Buck authored and ljharb committed Jun 3, 2016
1 parent 8df4943 commit d5bc7a7
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,18 @@ module.exports = {
}
const parentNodeIndent = getNodeIndent(node.parent);
checkNodesIndent(node, parentNodeIndent + indentSize);
},
ReturnStatement: function(node) {
if (!node.parent) {
return;
}

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

if (closingIndent !== openingIndent) {
report(node, openingIndent, closingIndent);
}
}
};
}
Expand Down
86 changes: 86 additions & 0 deletions tests/lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,26 @@ const Component = () => (
}
`,
options: [2, {indentLogicalExpressions: true}]
}, {
code: [
'function App() {',
' return (',
' <App />',
' );',
'}'
].join('\n'),
options: [2],
parserOptions: parserOptions
}, {
code: [
'function App() {',
' return <App>',
' <Foo />',
' </App>;',
'}'
].join('\n'),
options: [2],
parserOptions: parserOptions
}],

invalid: [{
Expand Down Expand Up @@ -1056,6 +1076,50 @@ const Component = () => (
].join('\n'),
options: [2],
errors: [{message: 'Expected indentation of 2 space characters but found 4.'}]
}, {
code: [
'function App() {',
' return (<App>',
' <Foo />',
' </App>);',
'}'
].join('\n'),
output: [
'function App() {',
' return (',
' <App>',
' <Foo />',
' </App>',
' );',
'}'
].join('\n'),
options: [2],
errors: [{
line: 5,
message: 'Expected indentation of 4 space characters but found 6.'
}]
}, {
code: [
'function App() {',
' return (<App>',
' <Foo />',
' </App>);',
'}'
].join('\n'),
output: [
'function App() {',
' return (',
' <App>',
' <Foo />',
' </App>',
' );',
'}'
].join('\n'),
options: [2],
errors: [{
line: 5,
message: 'Expected indentation of 4 space characters but found 6.'
}]
}, {
code: [
'function App() {',
Expand Down Expand Up @@ -1883,5 +1947,27 @@ const Component = () => (
errors: [
{message: 'Expected indentation of 8 space characters but found 4.'}
]
}, {
code: [
'function App() {',
' return (',
' <App />',
' );',
'}'
].join('\n'),
options: [2],
parserOptions: parserOptions,
errors: [{message: 'Expected indentation of 2 space characters but found 4.'}]
}, {
code: [
'function App() {',
' return (',
' <App />',
');',
'}'
].join('\n'),
options: [2],
parserOptions: parserOptions,
errors: [{message: 'Expected indentation of 2 space characters but found 0.'}]
}]
});

0 comments on commit d5bc7a7

Please sign in to comment.