Skip to content

Commit 393bfa2

Browse files
JulienR1ljharb
authored andcommitted
[Fix] no-object-type-as-default-prop: enable rule for components with many parameters
1 parent a944aa5 commit 393bfa2

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
99
* [`prop-types`]: null-check rootNode before calling getScope ([#3762][] @crnhrv)
1010
* [`boolean-prop-naming`]: avoid a crash with a spread prop ([#3733][] @ljharb)
1111
* [`jsx-boolean-value`]: `assumeUndefinedIsFalse` with `never` must not allow explicit `true` value ([#3757][] @6uliver)
12+
* [`no-object-type-as-default-prop`]: enable rule for components with many parameters ([#3768][] @JulienR1)
1213

14+
[#3768]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3768
1315
[#3762]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3762
1416
[#3757]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3757
1517
[#3733]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3733

lib/rules/no-object-type-as-default-prop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const messages = {
3030
function hasUsedObjectDestructuringSyntax(params) {
3131
return (
3232
params != null
33-
&& params.length === 1
33+
&& params.length >= 1
3434
&& params[0].type === 'ObjectPattern'
3535
);
3636
}

tests/lib/rules/no-object-type-as-default-prop.js

+23
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ ruleTester.run('no-object-type-as-default-prop', rule, {
143143
return null;
144144
};
145145
`,
146+
`
147+
const Foo = ({bar = 1}, context) => {
148+
return null;
149+
};
150+
`,
146151
`
147152
export default function NotAComponent({foo = {}}) {}
148153
`
@@ -183,6 +188,24 @@ ruleTester.run('no-object-type-as-default-prop', rule, {
183188
}
184189
`,
185190
errors: expectedViolations,
191+
},
192+
{
193+
code: `
194+
const Foo = ({
195+
a = {},
196+
b = ['one', 'two'],
197+
c = /regex/i,
198+
d = () => {},
199+
e = function() {},
200+
f = class {},
201+
g = new Thing(),
202+
h = <Thing />,
203+
i = Symbol('foo')
204+
}, context) => {
205+
return null;
206+
}
207+
`,
208+
errors: expectedViolations,
186209
}
187210
)),
188211
});

0 commit comments

Comments
 (0)