Skip to content

Commit 625010a

Browse files
committed
[Fix] jsx-indent: properly report on returned ternaries with jsx
Fixes #3222
1 parent a8fca2a commit 625010a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
88
### Fixed
99
* [`jsx-curly-brace-presence`]: avoid warning on curlies containing quote characters ([#3214][] @ljharb)
1010
* [`jsx-indent`]: do not report on non-jsx-returning ternaries that contain null ([#3222][] @ljharb)
11+
* [`jsx-indent`]: properly report on returned ternaries with jsx ([#3222][] @ljharb)
1112

1213
[#3222]: https://github.com/yannickcr/eslint-plugin-react/issues/3222
1314
[#3214]: https://github.com/yannickcr/eslint-plugin-react/issues/3214

lib/rules/jsx-indent.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,10 @@ module.exports = {
415415
JSXText: handleLiteral,
416416

417417
ReturnStatement(node) {
418-
if (!node.parent) {
418+
if (
419+
!node.parent
420+
|| !jsxUtil.isJSX(node.argument)
421+
) {
419422
return;
420423
}
421424

tests/lib/rules/jsx-indent.js

+10
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,16 @@ const Component = () => (
12191219
`,
12201220
options: [99],
12211221
},
1222+
{
1223+
code: `
1224+
function test (foo) {
1225+
return foo != null
1226+
? <div>foo</div>
1227+
: <div>bar</div>
1228+
}
1229+
`,
1230+
options: [2],
1231+
},
12221232
]),
12231233

12241234
invalid: parsers.all([].concat(

0 commit comments

Comments
 (0)