Skip to content

Commit eca2b73

Browse files
committed
fixes max props rule tests for defineProps with type-only declarion
1 parent 5bdfa40 commit eca2b73

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

docs/rules/max-props.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ description: enforce maximum number of props in Vue component
99

1010
> enforce maximum number of props in Vue component
1111
12-
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
12+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> _**This rule has not been released yet.**_ </badge>
1313

1414
## :book: Rule Details
1515

1616
This rule enforces a maximum number of props in a Vue SFC, in order to aid in maintainability and reduce complexity.
1717

18-
1918
## :wrench: Options
20-
This rule takes an object, where you can specify the maximum number of props allowed in a Vue SFC.
19+
20+
This rule takes an object, where you can specify the maximum number of props allowed in a Vue SFC.
2121
There is one property that can be specified for the object.
2222

2323
- `maxProps` ... Specify the maximum number of props in the `script` block.
@@ -41,7 +41,6 @@ defineProps({
4141

4242
</eslint-code-block>
4343

44-
4544
### `{ maxProps: 5 }`
4645

4746
<eslint-code-block :rules="{'vue/max-props': ['error', { maxProps: 5 }]}">
@@ -57,7 +56,6 @@ defineProps({
5756

5857
</eslint-code-block>
5958

60-
6159
Nothing.
6260

6361
## :mag: Implementation

lib/rules/max-props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module.exports = {
5656
}
5757

5858
return utils.compositingVisitors(
59-
utils.executeOnVueComponent(context, (obj) => {
59+
utils.executeOnVue(context, (obj) => {
6060
checkMaxNumberOfProps(utils.getComponentPropsFromOptions(obj))
6161
}),
6262
utils.defineScriptSetupVisitor(context, {

tests/lib/rules/max-props.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ tester.run('max-props', rule, {
102102
</script>
103103
`,
104104
options: [{ maxProps: 5 }]
105+
},
106+
{
107+
filename: 'test.vue',
108+
code: `
109+
<template>
110+
111+
</template>
112+
<script setup lang="ts">
113+
defineProps<{ prop1: string, prop2: string }>();
114+
</script>
115+
`,
116+
options: [{ maxProps: 5 }],
117+
languageOptions: {
118+
parser: require('vue-eslint-parser'),
119+
parserOptions: {
120+
parser: require.resolve('@typescript-eslint/parser')
121+
}
122+
}
105123
}
106124
],
107125
invalid: [
@@ -143,6 +161,29 @@ tester.run('max-props', rule, {
143161
line: 7
144162
}
145163
]
164+
},
165+
{
166+
filename: 'test.vue',
167+
code: `
168+
<template>
169+
</template>
170+
<script setup lang="ts">
171+
defineProps<{ prop1: string, prop2: string, prop3: string }>();
172+
</script>
173+
`,
174+
options: [{ maxProps: 2 }],
175+
languageOptions: {
176+
parser: require('vue-eslint-parser'),
177+
parserOptions: {
178+
parser: require.resolve('@typescript-eslint/parser')
179+
}
180+
},
181+
errors: [
182+
{
183+
message: 'Component has too many props (3). Maximum allowed is 2.',
184+
line: 5
185+
}
186+
]
146187
}
147188
]
148189
})

0 commit comments

Comments
 (0)