Skip to content

Commit 75fc825

Browse files
add new test case & update docs
1 parent 1183f8f commit 75fc825

File tree

2 files changed

+65
-21
lines changed

2 files changed

+65
-21
lines changed

lib/rules/force-types-on-object-props.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ module.exports = {
104104
'TSObjectKeyword'
105105
].includes(typeAnnotation.type) ||
106106
!typeAnnotation.typeName ||
107-
typeAnnotation.typeName.name !== 'Prop'
107+
!['Prop', 'PropType'].includes(typeAnnotation.typeName.name)
108108
) {
109109
context.report({
110110
node: prop,

tests/lib/rules/force-types-on-object-props.js

+64-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @author *****your name*****
2+
* @author Przemysław Jan Beigert
33
* See LICENSE file in root directory for full license.
44
*/
55
'use strict'
@@ -18,7 +18,8 @@ export default {
1818
}
1919
}
2020
</script>
21-
`
21+
`;
22+
2223

2324
const ruleTester = new RuleTester({
2425
parser: require.resolve('vue-eslint-parser'),
@@ -27,7 +28,11 @@ const ruleTester = new RuleTester({
2728
sourceType: 'module',
2829
parser: '@typescript-eslint/parser'
2930
}
30-
})
31+
});
32+
33+
const expectedError = {
34+
message: 'Expected type annotation on object prop.'
35+
};
3136

3237
ruleTester.run('force-types-on-object-props', rule, {
3338
valid: [
@@ -43,6 +48,18 @@ ruleTester.run('force-types-on-object-props', rule, {
4348
props: {}
4449
}
4550
</script>
51+
`,
52+
`
53+
<script setup>
54+
const props = defineProps(['foo']);
55+
</script>
56+
`,
57+
`
58+
<script setup>
59+
const props = defineProps({
60+
foo: String
61+
});
62+
</script>
4663
`,
4764
template('type: String'),
4865
template('foo: String,'),
@@ -58,42 +75,69 @@ ruleTester.run('force-types-on-object-props', rule, {
5875
{
5976
code: template('type: Object'),
6077
errors: [
61-
{
62-
message: 'Expected type annotation on object prop.'
63-
}
78+
expectedError
79+
]
80+
},
81+
{
82+
code: template('type: Object,'),
83+
errors: [
84+
expectedError
6485
]
6586
},
6687
{
6788
code: template('type: Object as any'),
6889
errors: [
69-
{
70-
message: 'Expected type annotation on object prop.'
71-
}
90+
expectedError
91+
]
92+
},
93+
{
94+
code: template('type: Object as any,'),
95+
errors: [
96+
expectedError
7297
]
7398
},
99+
74100
{
75101
code: template('type: Object as {}'),
76102
errors: [
77-
{
78-
message: 'Expected type annotation on object prop.'
79-
}
103+
expectedError
104+
]
105+
},
106+
{
107+
code: template('type: Object as {},'),
108+
errors: [
109+
expectedError
80110
]
81111
},
82112
{
83113
code: template('type: Object as unknown'),
84114
errors: [
85-
{
86-
message: 'Expected type annotation on object prop.'
87-
}
115+
expectedError
88116
]
89117
},
90118
{
91-
code: template('type: Object as string'),
119+
code: template('type: Object as () => any'),
92120
errors: [
93-
{
94-
message: 'Expected type annotation on object prop.'
95-
}
121+
expectedError
96122
]
97-
}
123+
},
124+
{
125+
code: template('type: Object as () => any,'),
126+
errors: [
127+
expectedError
128+
]
129+
},
130+
{
131+
code: template('type: Object as () => unknown'),
132+
errors: [
133+
expectedError
134+
]
135+
},
136+
{
137+
code: template('type: Object as () => unknown,'),
138+
errors: [
139+
expectedError
140+
]
141+
},
98142
]
99143
})

0 commit comments

Comments
 (0)