Skip to content

Commit e316606

Browse files
committed
Fix vue/require-prop-type-constructor
1 parent 03ddd6f commit e316606

File tree

3 files changed

+62
-15
lines changed

3 files changed

+62
-15
lines changed

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

+14-13
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ module.exports = {
4545
}
4646
}
4747

48-
const checkPropertyNode = (p) => {
49-
if (isForbiddenType(p.value)) {
48+
const checkPropertyNode = (key, node) => {
49+
if (isForbiddenType(node)) {
5050
context.report({
51-
node: p.value,
51+
node: node,
5252
message,
5353
data: {
54-
name: utils.getStaticPropertyName(p.key)
54+
name: utils.getStaticPropertyName(key)
5555
},
56-
fix: fix(p.value)
56+
fix: fix(node)
5757
})
58-
} else if (p.value.type === 'ArrayExpression') {
59-
p.value.elements
58+
} else if (node.type === 'ArrayExpression') {
59+
node.elements
6060
.filter(prop => isForbiddenType(prop))
6161
.forEach(prop => context.report({
6262
node: prop,
6363
message,
6464
data: {
65-
name: utils.getStaticPropertyName(p.key)
65+
name: utils.getStaticPropertyName(key)
6666
},
6767
fix: fix(prop)
6868
}))
@@ -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)
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(typeProperty)
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

+30-2
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ ruleTester.run('require-prop-type-constructor', rule, {
9191
message: 'The "anotherType" property should be a constructor.',
9292
line: 5
9393
}, {
94-
message: 'The "type" property should be a constructor.',
94+
message: 'The "extraProp" property should be a constructor.',
9595
line: 7
9696
}, {
97-
message: 'The "type" property should be a constructor.',
97+
message: 'The "lastProp" property should be a constructor.',
9898
line: 11
9999
}, {
100100
message: 'The "nullProp" property should be a constructor.',
@@ -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)