Skip to content

Commit b8b04f4

Browse files
committed
Fix false positives for quoted 'emits' in vue/require-explicit-emits rule
1 parent 6894340 commit b8b04f4

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

lib/utils/index.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,7 @@ module.exports = {
544544
(p) => {
545545
return (
546546
p.type === 'Property' &&
547-
p.key.type === 'Identifier' &&
548-
p.key.name === 'components' &&
547+
getStaticPropertyName(p) === 'components' &&
549548
p.value.type === 'ObjectExpression'
550549
)
551550
}
@@ -677,8 +676,7 @@ module.exports = {
677676
(p) => {
678677
return (
679678
p.type === 'Property' &&
680-
p.key.type === 'Identifier' &&
681-
p.key.name === 'props' &&
679+
getStaticPropertyName(p) === 'props' &&
682680
(p.value.type === 'ObjectExpression' ||
683681
p.value.type === 'ArrayExpression')
684682
)
@@ -748,8 +746,7 @@ module.exports = {
748746
(p) => {
749747
return (
750748
p.type === 'Property' &&
751-
p.key.type === 'Identifier' &&
752-
p.key.name === 'emits' &&
749+
getStaticPropertyName(p) === 'emits' &&
753750
(p.value.type === 'ObjectExpression' ||
754751
p.value.type === 'ArrayExpression')
755752
)
@@ -819,8 +816,7 @@ module.exports = {
819816
(p) => {
820817
return (
821818
p.type === 'Property' &&
822-
p.key.type === 'Identifier' &&
823-
p.key.name === 'computed' &&
819+
getStaticPropertyName(p) === 'computed' &&
824820
p.value.type === 'ObjectExpression'
825821
)
826822
}

tests/lib/rules/require-explicit-emits.js

+14
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@ tester.run('require-explicit-emits', rule, {
140140
</script>
141141
`
142142
},
143+
// quoted
144+
{
145+
filename: 'test.vue',
146+
code: `
147+
<template>
148+
<div @click="$emit('welcome')"/>
149+
</template>
150+
<script>
151+
export default {
152+
'emits': ['welcome']
153+
}
154+
</script>
155+
`
156+
},
143157
// unknown
144158
{
145159
filename: 'test.vue',

tests/lib/rules/return-in-computed-property.js

+17
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,23 @@ ruleTester.run('return-in-computed-property', rule, {
394394
line: 5
395395
}
396396
]
397+
},
398+
{
399+
filename: 'test.vue',
400+
code: `
401+
export default {
402+
'computed': {
403+
foo() {
404+
}
405+
}
406+
}`,
407+
parserOptions,
408+
errors: [
409+
{
410+
message: 'Expected to return a value in "foo" computed property.',
411+
line: 4
412+
}
413+
]
397414
}
398415
]
399416
})

0 commit comments

Comments
 (0)