Skip to content

Commit

Permalink
[Fix] jsx-indent: properly report on returned ternaries with jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 25, 2022
1 parent a8fca2a commit 625010a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
### Fixed
* [`jsx-curly-brace-presence`]: avoid warning on curlies containing quote characters ([#3214][] @ljharb)
* [`jsx-indent`]: do not report on non-jsx-returning ternaries that contain null ([#3222][] @ljharb)
* [`jsx-indent`]: properly report on returned ternaries with jsx ([#3222][] @ljharb)

[#3222]: https://github.com/yannickcr/eslint-plugin-react/issues/3222
[#3214]: https://github.com/yannickcr/eslint-plugin-react/issues/3214
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,10 @@ module.exports = {
JSXText: handleLiteral,

ReturnStatement(node) {
if (!node.parent) {
if (
!node.parent
|| !jsxUtil.isJSX(node.argument)
) {
return;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,16 @@ const Component = () => (
`,
options: [99],
},
{
code: `
function test (foo) {
return foo != null
? <div>foo</div>
: <div>bar</div>
}
`,
options: [2],
},
]),

invalid: parsers.all([].concat(
Expand Down

0 comments on commit 625010a

Please sign in to comment.