From a79beb364f297571af9d368e1d5c35f56f84a8a7 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 31 May 2024 16:46:05 -0700 Subject: [PATCH] [Fix] `boolean-prop-naming`: avoid a crash with a spread prop Fixes #3733 --- CHANGELOG.md | 2 ++ lib/rules/boolean-prop-naming.js | 2 +- tests/lib/rules/boolean-prop-naming.js | 22 +++++++++++++++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4bccfaa25..bef2238f72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,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) [#3762]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3762 +[#3733]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3733 ## [7.34.2] - 2024.05.24 diff --git a/lib/rules/boolean-prop-naming.js b/lib/rules/boolean-prop-naming.js index f64da93242..e6ea400025 100644 --- a/lib/rules/boolean-prop-naming.js +++ b/lib/rules/boolean-prop-naming.js @@ -399,7 +399,7 @@ module.exports = { } if (propType) { - [].concat(propType).forEach((prop) => { + [].concat(propType).filter(Boolean).forEach((prop) => { validatePropNaming( component.node, prop.properties || prop.members || prop.body diff --git a/tests/lib/rules/boolean-prop-naming.js b/tests/lib/rules/boolean-prop-naming.js index 2dec7ed70c..10ff9097f2 100644 --- a/tests/lib/rules/boolean-prop-naming.js +++ b/tests/lib/rules/boolean-prop-naming.js @@ -415,7 +415,6 @@ ruleTester.run('boolean-prop-naming', rule, { `, options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }], features: ['ts'], - errors: [], }, { code: ` @@ -426,7 +425,6 @@ ruleTester.run('boolean-prop-naming', rule, { `, options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }], features: ['types'], - errors: [], }, { code: ` @@ -439,7 +437,6 @@ ruleTester.run('boolean-prop-naming', rule, { `, options: [{ rule: '(is|has)[A-Z]([A-Za-z0-9]?)+' }], features: ['types'], - errors: [], }, { code: ` @@ -451,7 +448,6 @@ ruleTester.run('boolean-prop-naming', rule, { `, options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }], features: ['types'], - errors: [], }, { code: ` @@ -465,7 +461,6 @@ ruleTester.run('boolean-prop-naming', rule, { `, options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }], features: ['types'], - errors: [], }, { code: ` @@ -479,7 +474,6 @@ ruleTester.run('boolean-prop-naming', rule, { `, options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }], features: ['types'], - errors: [], }, { code: ` @@ -495,7 +489,21 @@ ruleTester.run('boolean-prop-naming', rule, { `, options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }], features: ['types'], - errors: [], + }, + { + code: ` + export const DataRow = (props: { label: string; value: string; } & React.HTMLAttributes) => { + const { label, value, ...otherProps } = props; + return ( +
+ {label} + {value} +
+ ); + }; + `, + options: [{ rule: '(^(is|has|should|without)[A-Z]([A-Za-z0-9]?)+|disabled|required|checked|defaultChecked)' }], + features: ['types'], }, ]),