Skip to content

Commit a79beb3

Browse files
committed
[Fix] boolean-prop-naming: avoid a crash with a spread prop
Fixes #3733
1 parent e27ef81 commit a79beb3

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
77

88
### Fixed
99
* [`prop-types`]: null-check rootNode before calling getScope ([#3762][] @crnhrv)
10+
* [`boolean-prop-naming`]: avoid a crash with a spread prop ([#3733][] @ljharb)
1011

1112
[#3762]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3762
13+
[#3733]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3733
1214

1315
## [7.34.2] - 2024.05.24
1416

lib/rules/boolean-prop-naming.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ module.exports = {
399399
}
400400

401401
if (propType) {
402-
[].concat(propType).forEach((prop) => {
402+
[].concat(propType).filter(Boolean).forEach((prop) => {
403403
validatePropNaming(
404404
component.node,
405405
prop.properties || prop.members || prop.body

tests/lib/rules/boolean-prop-naming.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ ruleTester.run('boolean-prop-naming', rule, {
415415
`,
416416
options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }],
417417
features: ['ts'],
418-
errors: [],
419418
},
420419
{
421420
code: `
@@ -426,7 +425,6 @@ ruleTester.run('boolean-prop-naming', rule, {
426425
`,
427426
options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }],
428427
features: ['types'],
429-
errors: [],
430428
},
431429
{
432430
code: `
@@ -439,7 +437,6 @@ ruleTester.run('boolean-prop-naming', rule, {
439437
`,
440438
options: [{ rule: '(is|has)[A-Z]([A-Za-z0-9]?)+' }],
441439
features: ['types'],
442-
errors: [],
443440
},
444441
{
445442
code: `
@@ -451,7 +448,6 @@ ruleTester.run('boolean-prop-naming', rule, {
451448
`,
452449
options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }],
453450
features: ['types'],
454-
errors: [],
455451
},
456452
{
457453
code: `
@@ -465,7 +461,6 @@ ruleTester.run('boolean-prop-naming', rule, {
465461
`,
466462
options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }],
467463
features: ['types'],
468-
errors: [],
469464
},
470465
{
471466
code: `
@@ -479,7 +474,6 @@ ruleTester.run('boolean-prop-naming', rule, {
479474
`,
480475
options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }],
481476
features: ['types'],
482-
errors: [],
483477
},
484478
{
485479
code: `
@@ -495,7 +489,21 @@ ruleTester.run('boolean-prop-naming', rule, {
495489
`,
496490
options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }],
497491
features: ['types'],
498-
errors: [],
492+
},
493+
{
494+
code: `
495+
export const DataRow = (props: { label: string; value: string; } & React.HTMLAttributes<HTMLDivElement>) => {
496+
const { label, value, ...otherProps } = props;
497+
return (
498+
<div {...otherProps}>
499+
<span>{label}</span>
500+
<span>{value}</span>
501+
</div>
502+
);
503+
};
504+
`,
505+
options: [{ rule: '(^(is|has|should|without)[A-Z]([A-Za-z0-9]?)+|disabled|required|checked|defaultChecked)' }],
506+
features: ['types'],
499507
},
500508
]),
501509

0 commit comments

Comments
 (0)