Skip to content

Commit

Permalink
fix: Prevent spread operator from disabling the rule (#2456)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGuerinPP authored May 9, 2024
1 parent f0aa5dc commit 98e030a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
49 changes: 49 additions & 0 deletions tests/lib/rules/require-default-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,28 @@ ruleTester.run('require-default-prop', rule, {
...languageOptions,
parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
}
},
{
filename: 'test.vue',
code: `
<script setup lang="ts">
const defaultProps = {
foo: 'foo',
}
withDefaults(defineProps<{
foo: string;
bar?: number;
}>(), {
...defaultProps,
bar: 42,
})
</script>
`,
languageOptions: {
parser: require('vue-eslint-parser'),
...languageOptions,
parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
}
}
],

Expand Down Expand Up @@ -544,6 +566,33 @@ ruleTester.run('require-default-prop', rule, {
...languageOptions
}
},
{
filename: 'test.vue',
code: `
<script setup lang="ts">
const defaultProps = {
foo: 'foo',
}
withDefaults(defineProps<{
foo: string;
bar?: number;
}>(), {
...defaultProps,
})
</script>
`,
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'
Expand Down

0 comments on commit 98e030a

Please sign in to comment.