Skip to content

Commit

Permalink
[Fix] no-object-type-as-default-prop: enable rule for components wi…
Browse files Browse the repository at this point in the history
…th many parameters
  • Loading branch information
JulienR1 authored and ljharb committed Jun 13, 2024
1 parent a944aa5 commit 393bfa2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [`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)
* [`no-object-type-as-default-prop`]: enable rule for components with many parameters ([#3768][] @JulienR1)

[#3768]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3768
[#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
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-object-type-as-default-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const messages = {
function hasUsedObjectDestructuringSyntax(params) {
return (
params != null
&& params.length === 1
&& params.length >= 1
&& params[0].type === 'ObjectPattern'
);
}
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/rules/no-object-type-as-default-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ ruleTester.run('no-object-type-as-default-prop', rule, {
return null;
};
`,
`
const Foo = ({bar = 1}, context) => {
return null;
};
`,
`
export default function NotAComponent({foo = {}}) {}
`
Expand Down Expand Up @@ -183,6 +188,24 @@ ruleTester.run('no-object-type-as-default-prop', rule, {
}
`,
errors: expectedViolations,
},
{
code: `
const Foo = ({
a = {},
b = ['one', 'two'],
c = /regex/i,
d = () => {},
e = function() {},
f = class {},
g = new Thing(),
h = <Thing />,
i = Symbol('foo')
}, context) => {
return null;
}
`,
errors: expectedViolations,
}
)),
});

0 comments on commit 393bfa2

Please sign in to comment.