Skip to content

Commit 3e6cc15

Browse files
author
Stefan Buck
committed
[Fix] jsx-indent: Fix indent handling for closing parentheses
Fixes jsx-eslint#618.
1 parent 8df4943 commit 3e6cc15

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

lib/rules/jsx-indent.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,18 @@ module.exports = {
352352
}
353353
const parentNodeIndent = getNodeIndent(node.parent);
354354
checkNodesIndent(node, parentNodeIndent + indentSize);
355+
},
356+
ReturnStatement(node) {
357+
if (!node.parent) {
358+
return;
359+
}
360+
361+
const openingIndent = getNodeIndent(node);
362+
const closingIndent = getNodeIndent(node, true);
363+
364+
if (closingIndent !== openingIndent) {
365+
report(node, openingIndent, closingIndent);
366+
}
355367
}
356368
};
357369
}

tests/lib/rules/jsx-indent.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,26 @@ const Component = () => (
956956
}
957957
`,
958958
options: [2, {indentLogicalExpressions: true}]
959+
}, {
960+
code: [
961+
'function App() {',
962+
' return (',
963+
' <App />',
964+
' );',
965+
'}'
966+
].join('\n'),
967+
options: [2],
968+
parserOptions
969+
}, {
970+
code: [
971+
'function App() {',
972+
' return <App>',
973+
' <Foo />',
974+
' </App>;',
975+
'}'
976+
].join('\n'),
977+
options: [2],
978+
parserOptions
959979
}],
960980

961981
invalid: [{
@@ -1038,7 +1058,10 @@ const Component = () => (
10381058
'}'
10391059
].join('\n'),
10401060
options: [2],
1041-
errors: [{message: 'Expected indentation of 2 space characters but found 9.'}]
1061+
errors: [
1062+
{message: 'Expected indentation of 2 space characters but found 9.'},
1063+
{message: 'Expected indentation of 2 space characters but found 9.'}
1064+
]
10421065
}, {
10431066
code: [
10441067
'function App() {',
@@ -1055,7 +1078,10 @@ const Component = () => (
10551078
'}'
10561079
].join('\n'),
10571080
options: [2],
1058-
errors: [{message: 'Expected indentation of 2 space characters but found 4.'}]
1081+
errors: [
1082+
{message: 'Expected indentation of 2 space characters but found 4.'},
1083+
{message: 'Expected indentation of 2 space characters but found 4.'}
1084+
]
10591085
}, {
10601086
code: [
10611087
'function App() {',
@@ -1883,5 +1909,27 @@ const Component = () => (
18831909
errors: [
18841910
{message: 'Expected indentation of 8 space characters but found 4.'}
18851911
]
1912+
}, {
1913+
code: [
1914+
'function App() {',
1915+
' return (',
1916+
' <App />',
1917+
' );',
1918+
'}'
1919+
].join('\n'),
1920+
options: [2],
1921+
parserOptions,
1922+
errors: [{message: 'Expected indentation of 2 space characters but found 4.'}]
1923+
}, {
1924+
code: [
1925+
'function App() {',
1926+
' return (',
1927+
' <App />',
1928+
');',
1929+
'}'
1930+
].join('\n'),
1931+
options: [2],
1932+
parserOptions,
1933+
errors: [{message: 'Expected indentation of 2 space characters but found 0.'}]
18861934
}]
18871935
});

0 commit comments

Comments
 (0)