Skip to content

Commit

Permalink
[Fix] boolean-prop-naming: avoid a crash with a spread prop
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed May 31, 2024
1 parent e27ef81 commit a79beb3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 15 additions & 7 deletions tests/lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ ruleTester.run('boolean-prop-naming', rule, {
`,
options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }],
features: ['ts'],
errors: [],
},
{
code: `
Expand All @@ -426,7 +425,6 @@ ruleTester.run('boolean-prop-naming', rule, {
`,
options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }],
features: ['types'],
errors: [],
},
{
code: `
Expand All @@ -439,7 +437,6 @@ ruleTester.run('boolean-prop-naming', rule, {
`,
options: [{ rule: '(is|has)[A-Z]([A-Za-z0-9]?)+' }],
features: ['types'],
errors: [],
},
{
code: `
Expand All @@ -451,7 +448,6 @@ ruleTester.run('boolean-prop-naming', rule, {
`,
options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }],
features: ['types'],
errors: [],
},
{
code: `
Expand All @@ -465,7 +461,6 @@ ruleTester.run('boolean-prop-naming', rule, {
`,
options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }],
features: ['types'],
errors: [],
},
{
code: `
Expand All @@ -479,7 +474,6 @@ ruleTester.run('boolean-prop-naming', rule, {
`,
options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }],
features: ['types'],
errors: [],
},
{
code: `
Expand All @@ -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<HTMLDivElement>) => {
const { label, value, ...otherProps } = props;
return (
<div {...otherProps}>
<span>{label}</span>
<span>{value}</span>
</div>
);
};
`,
options: [{ rule: '(^(is|has|should|without)[A-Z]([A-Za-z0-9]?)+|disabled|required|checked|defaultChecked)' }],
features: ['types'],
},
]),

Expand Down

0 comments on commit a79beb3

Please sign in to comment.