From 98e030adc02e118c17031491b6b85f9735418eba Mon Sep 17 00:00:00 2001
From: Guillaume Guerin <146925467+GuillaumeGuerinPP@users.noreply.github.com>
Date: Thu, 9 May 2024 04:18:43 +0200
Subject: [PATCH] fix: Prevent spread operator from disabling the rule (#2456)
---
lib/utils/index.js | 2 +-
tests/lib/rules/require-default-prop.js | 49 +++++++++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/lib/utils/index.js b/lib/utils/index.js
index b6dcdb8ce..9671c00d4 100644
--- a/lib/utils/index.js
+++ b/lib/utils/index.js
@@ -3133,7 +3133,7 @@ function getWithDefaultsProps(node) {
for (const prop of param.properties) {
if (prop.type !== 'Property') {
- return {}
+ continue
}
const name = getStaticPropertyName(prop)
if (name != null) {
diff --git a/tests/lib/rules/require-default-prop.js b/tests/lib/rules/require-default-prop.js
index 97aea4919..834f319aa 100644
--- a/tests/lib/rules/require-default-prop.js
+++ b/tests/lib/rules/require-default-prop.js
@@ -329,6 +329,28 @@ ruleTester.run('require-default-prop', rule, {
...languageOptions,
parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
}
+ },
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ languageOptions: {
+ parser: require('vue-eslint-parser'),
+ ...languageOptions,
+ parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
+ }
}
],
@@ -544,6 +566,33 @@ ruleTester.run('require-default-prop', rule, {
...languageOptions
}
},
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ errors: [
+ {
+ message: "Prop 'bar' requires default value to be set.",
+ line: 8
+ }
+ ],
+ languageOptions: {
+ parser: require('vue-eslint-parser'),
+ ...languageOptions,
+ parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
+ }
+ },
...(semver.lt(
require('@typescript-eslint/parser/package.json').version,
'4.0.0'