Skip to content

Commit a944aa5

Browse files
6uliverljharb
authored andcommitted
[Fix] jsx-boolean-value: assumeUndefinedIsFalse with never must not allow explicit true value
1 parent a79beb3 commit a944aa5

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
88
### Fixed
99
* [`prop-types`]: null-check rootNode before calling getScope ([#3762][] @crnhrv)
1010
* [`boolean-prop-naming`]: avoid a crash with a spread prop ([#3733][] @ljharb)
11+
* [`jsx-boolean-value`]: `assumeUndefinedIsFalse` with `never` must not allow explicit `true` value ([#3757][] @6uliver)
1112

1213
[#3762]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3762
14+
[#3757]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3757
1315
[#3733]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3733
1416

1517
## [7.34.2] - 2024.05.24

lib/rules/jsx-boolean-value.js

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ module.exports = {
132132
}
133133
if (
134134
isNever(configuration, exceptions, propName)
135-
&& !configObject.assumeUndefinedIsFalse
136135
&& value
137136
&& value.type === 'JSXExpressionContainer'
138137
&& value.expression.value === true

tests/lib/rules/jsx-boolean-value.js

+19
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ ruleTester.run('jsx-boolean-value', rule, {
5252
code: '<App />;',
5353
options: ['never', { assumeUndefinedIsFalse: true }],
5454
},
55+
{
56+
code: '<App foo={false} />;',
57+
options: ['never', { assumeUndefinedIsFalse: false }],
58+
},
5559
{
5660
code: '<App foo={false} />;',
5761
options: ['never', { assumeUndefinedIsFalse: true, always: ['foo'] }],
@@ -145,6 +149,21 @@ ruleTester.run('jsx-boolean-value', rule, {
145149
},
146150
],
147151
},
152+
{
153+
code: '<App foo={true} bak={false} />;',
154+
output: '<App foo />;',
155+
options: ['never', { assumeUndefinedIsFalse: true }],
156+
errors: [
157+
{
158+
messageId: 'omitBoolean',
159+
data: { propName: 'foo' },
160+
},
161+
{
162+
messageId: 'omitPropAndBoolean',
163+
data: { propName: 'bak' },
164+
},
165+
],
166+
},
148167
{
149168
code: '<App foo={true} bar={false} baz={false} bak={false} />;',
150169
output: '<App foo={true} bar={false} />;',

0 commit comments

Comments
 (0)