Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] jsx-boolean-value: assumeUndefinedIsFalse with never must not allow explicit true value #3757

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading