Skip to content

Commit 12d8b40

Browse files
Stefan Buckljharb
Stefan Buck
authored andcommitted
[Fix] jsx-indent: Fix indent handling for closing parentheses
Fixes jsx-eslint#618.
1 parent aeff5ea commit 12d8b40

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

lib/rules/jsx-indent.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,19 @@ module.exports = {
395395
checkNodesIndent(node, parentNodeIndent + indentSize);
396396
},
397397
Literal: handleLiteral,
398-
JSXText: handleLiteral
398+
JSXText: handleLiteral,
399+
ReturnStatement(node) {
400+
if (!node.parent) {
401+
return;
402+
}
403+
404+
const openingIndent = getNodeIndent(node);
405+
const closingIndent = getNodeIndent(node, true);
406+
407+
if (closingIndent !== openingIndent) {
408+
report(node, openingIndent, closingIndent);
409+
}
410+
}
399411
};
400412
}
401413
};

tests/lib/rules/jsx-indent.js

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,26 @@ const Component = () => (
997997
'const b = `b\nb`;',
998998
'}'
999999
].join('\n')
1000+
}, {
1001+
code: [
1002+
'function App() {',
1003+
' return (',
1004+
' <App />',
1005+
' );',
1006+
'}'
1007+
].join('\n'),
1008+
options: [2],
1009+
parserOptions
1010+
}, {
1011+
code: [
1012+
'function App() {',
1013+
' return <App>',
1014+
' <Foo />',
1015+
' </App>;',
1016+
'}'
1017+
].join('\n'),
1018+
options: [2],
1019+
parserOptions
10001020
}],
10011021

10021022
invalid: [{
@@ -1102,7 +1122,10 @@ const Component = () => (
11021122
'}'
11031123
].join('\n'),
11041124
options: [2],
1105-
errors: [{message: 'Expected indentation of 2 space characters but found 9.'}]
1125+
errors: [
1126+
{message: 'Expected indentation of 2 space characters but found 9.'},
1127+
{message: 'Expected indentation of 2 space characters but found 9.'}
1128+
]
11061129
}, {
11071130
code: [
11081131
'function App() {',
@@ -1119,7 +1142,10 @@ const Component = () => (
11191142
'}'
11201143
].join('\n'),
11211144
options: [2],
1122-
errors: [{message: 'Expected indentation of 2 space characters but found 4.'}]
1145+
errors: [
1146+
{message: 'Expected indentation of 2 space characters but found 4.'},
1147+
{message: 'Expected indentation of 2 space characters but found 4.'}
1148+
]
11231149
}, {
11241150
code: [
11251151
'function App() {',
@@ -2033,5 +2059,41 @@ const Component = () => (
20332059
errors: [
20342060
{message: 'Expected indentation of 4 space characters but found 0.'}
20352061
]
2062+
}, {
2063+
code: [
2064+
'function App() {',
2065+
' return (',
2066+
' <App />',
2067+
' );',
2068+
'}'
2069+
].join('\n'),
2070+
output: [
2071+
'function App() {',
2072+
' return (',
2073+
' <App />',
2074+
' );',
2075+
'}'
2076+
].join('\n'),
2077+
options: [2],
2078+
parserOptions,
2079+
errors: [{message: 'Expected indentation of 2 space characters but found 4.'}]
2080+
}, {
2081+
code: [
2082+
'function App() {',
2083+
' return (',
2084+
' <App />',
2085+
');',
2086+
'}'
2087+
].join('\n'),
2088+
output: [
2089+
'function App() {',
2090+
' return (',
2091+
' <App />',
2092+
' );',
2093+
'}'
2094+
].join('\n'),
2095+
options: [2],
2096+
parserOptions,
2097+
errors: [{message: 'Expected indentation of 2 space characters but found 0.'}]
20362098
}]
20372099
});

0 commit comments

Comments
 (0)