Skip to content

Commit

Permalink
[Fix] jsx-indent: do not report on non-jsx-returning ternaries that…
Browse files Browse the repository at this point in the history
… contain null

Fixes #3222
  • Loading branch information
ljharb committed Feb 25, 2022
1 parent fe708e1 commit a8fca2a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ 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)

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

## [7.29.1] - 2022.02.25
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ module.exports = {
}
if (
!fn
|| !jsxUtil.isReturningJSX((n) => isCreateElement(n, context), node, context)
|| !jsxUtil.isReturningJSX((n) => isCreateElement(n, context), node, context, true)
) {
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 @@ -1209,6 +1209,16 @@ const Component = () => (
features: ['class fields'],
options: [2],
},
{
code: `
function test (foo) {
return foo != null
? Math.max(0, Math.min(1, 10))
: 0
}
`,
options: [99],
},
]),

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

0 comments on commit a8fca2a

Please sign in to comment.