From 62e763810b5d306cbba57d03523889bbabc38b45 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 --- lib/rules/no-object-type-as-default-prop.js | 2 +- .../rules/no-object-type-as-default-prop.js | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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, } )), });