Skip to content

Commit

Permalink
[Fix] jsx-boolean-value: assumeUndefinedIsFalse with never must…
Browse files Browse the repository at this point in the history
… not allow explicit `true` value
  • Loading branch information
6uliver authored and ljharb committed May 14, 2024
1 parent a79beb3 commit a944aa5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
### Fixed
* [`prop-types`]: null-check rootNode before calling getScope ([#3762][] @crnhrv)
* [`boolean-prop-naming`]: avoid a crash with a spread prop ([#3733][] @ljharb)
* [`jsx-boolean-value`]: `assumeUndefinedIsFalse` with `never` must not allow explicit `true` value ([#3757][] @6uliver)

[#3762]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3762
[#3757]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3757
[#3733]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3733

## [7.34.2] - 2024.05.24
Expand Down
1 change: 0 additions & 1 deletion lib/rules/jsx-boolean-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ module.exports = {
}
if (
isNever(configuration, exceptions, propName)
&& !configObject.assumeUndefinedIsFalse
&& value
&& value.type === 'JSXExpressionContainer'
&& value.expression.value === true
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rules/jsx-boolean-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ ruleTester.run('jsx-boolean-value', rule, {
code: '<App />;',
options: ['never', { assumeUndefinedIsFalse: true }],
},
{
code: '<App foo={false} />;',
options: ['never', { assumeUndefinedIsFalse: false }],
},
{
code: '<App foo={false} />;',
options: ['never', { assumeUndefinedIsFalse: true, always: ['foo'] }],
Expand Down Expand Up @@ -145,6 +149,21 @@ ruleTester.run('jsx-boolean-value', rule, {
},
],
},
{
code: '<App foo={true} bak={false} />;',
output: '<App foo />;',
options: ['never', { assumeUndefinedIsFalse: true }],
errors: [
{
messageId: 'omitBoolean',
data: { propName: 'foo' },
},
{
messageId: 'omitPropAndBoolean',
data: { propName: 'bak' },
},
],
},
{
code: '<App foo={true} bar={false} baz={false} bak={false} />;',
output: '<App foo={true} bar={false} />;',
Expand Down

0 comments on commit a944aa5

Please sign in to comment.