From 393bfa2fc071bfd08cef2327790e2ccc95507d72 Mon Sep 17 00:00:00 2001 From: Julien Rousseau Date: Wed, 12 Jun 2024 20:49:45 -0400 Subject: [PATCH] [Fix] `no-object-type-as-default-prop`: enable rule for components with many parameters --- CHANGELOG.md | 2 ++ lib/rules/no-object-type-as-default-prop.js | 2 +- .../rules/no-object-type-as-default-prop.js | 23 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b9d9ed001..cd3540427d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rules/no-object-type-as-default-prop.js b/lib/rules/no-object-type-as-default-prop.js index 7be98cb4b3..42012413e1 100644 --- a/lib/rules/no-object-type-as-default-prop.js +++ b/lib/rules/no-object-type-as-default-prop.js @@ -30,7 +30,7 @@ const messages = { function hasUsedObjectDestructuringSyntax(params) { return ( params != null - && params.length === 1 + && params.length >= 1 && params[0].type === 'ObjectPattern' ); } diff --git a/tests/lib/rules/no-object-type-as-default-prop.js b/tests/lib/rules/no-object-type-as-default-prop.js index e2660fb938..b515ef6a49 100644 --- a/tests/lib/rules/no-object-type-as-default-prop.js +++ b/tests/lib/rules/no-object-type-as-default-prop.js @@ -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 = {}}) {} ` @@ -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 = , + i = Symbol('foo') + }, context) => { + return null; + } + `, + errors: expectedViolations, } )), });