Skip to content

Commit 6f54a49

Browse files
committed
Fix vue/require-prop-type-constructor
1 parent 932a90a commit 6f54a49

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

Diff for: lib/rules/require-prop-type-constructor.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,18 @@ module.exports = {
8181

8282
node.value.properties
8383
.forEach(p => {
84-
if (isForbiddenType(p.value) || p.value.type === 'ArrayExpression') {
85-
checkPropertyNode(p.key, p.value)
86-
} else if (p.value.type === 'ObjectExpression') {
87-
const typeProperty = p.value.properties.find(prop =>
84+
const pValue = utils.unwrapTypes(p.value)
85+
if (isForbiddenType(pValue) || pValue.type === 'ArrayExpression') {
86+
checkPropertyNode(p.key, pValue)
87+
} else if (pValue.type === 'ObjectExpression') {
88+
const typeProperty = pValue.properties.find(prop =>
8889
prop.type === 'Property' &&
8990
prop.key.name === 'type'
9091
)
9192

9293
if (!typeProperty) return
9394

94-
checkPropertyNode(p.key, typeProperty.value)
95+
checkPropertyNode(p.key, utils.unwrapTypes(typeProperty.value))
9596
}
9697
})
9798
})

Diff for: tests/lib/rules/no-side-effects-in-computed-properties.js

+18
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,24 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
248248
line: 23,
249249
message: 'Unexpected side effect in "test4" computed property.'
250250
}]
251+
},
252+
{
253+
filename: 'test.vue',
254+
code: `
255+
export default Vue.extend({
256+
computed: {
257+
test1() : string {
258+
return this.something.reverse()
259+
}
260+
}
261+
});
262+
`,
263+
parserOptions,
264+
errors: [{
265+
line: 5,
266+
message: 'Unexpected side effect in "test1" computed property.'
267+
}],
268+
parser: 'typescript-eslint-parser'
251269
}
252270
]
253271
})

Diff for: tests/lib/rules/require-prop-type-constructor.js

+28
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,34 @@ ruleTester.run('require-prop-type-constructor', rule, {
136136
message: 'The "d" property should be a constructor.',
137137
line: 7
138138
}]
139+
},
140+
{
141+
filename: 'SomeComponent.vue',
142+
code: `
143+
export default {
144+
props: {
145+
a: {
146+
type: 'String',
147+
default: 10
148+
} as PropOptions<string>,
149+
}
150+
}
151+
`,
152+
output: `
153+
export default {
154+
props: {
155+
a: {
156+
type: String,
157+
default: 10
158+
} as PropOptions<string>,
159+
}
160+
}
161+
`,
162+
errors: [{
163+
message: 'The "a" property should be a constructor.',
164+
line: 5
165+
}],
166+
parser: 'typescript-eslint-parser'
139167
}
140168
]
141169
})

0 commit comments

Comments
 (0)