Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] no-object-type-as-default-prop: enable rule when multiple parameters #3768

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
)),
});