Skip to content

Commit

Permalink
Fix false positives for quoted 'emits' in vue/require-explicit-emits …
Browse files Browse the repository at this point in the history
…rule (#1420)
  • Loading branch information
ota-meshi committed Jan 22, 2021
1 parent 2d290b2 commit bbbb6ca
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/utils/index.js
Expand Up @@ -544,8 +544,7 @@ module.exports = {
(p) => {
return (
p.type === 'Property' &&
p.key.type === 'Identifier' &&
p.key.name === 'components' &&
getStaticPropertyName(p) === 'components' &&
p.value.type === 'ObjectExpression'
)
}
Expand Down Expand Up @@ -677,8 +676,7 @@ module.exports = {
(p) => {
return (
p.type === 'Property' &&
p.key.type === 'Identifier' &&
p.key.name === 'props' &&
getStaticPropertyName(p) === 'props' &&
(p.value.type === 'ObjectExpression' ||
p.value.type === 'ArrayExpression')
)
Expand Down Expand Up @@ -748,8 +746,7 @@ module.exports = {
(p) => {
return (
p.type === 'Property' &&
p.key.type === 'Identifier' &&
p.key.name === 'emits' &&
getStaticPropertyName(p) === 'emits' &&
(p.value.type === 'ObjectExpression' ||
p.value.type === 'ArrayExpression')
)
Expand Down Expand Up @@ -819,8 +816,7 @@ module.exports = {
(p) => {
return (
p.type === 'Property' &&
p.key.type === 'Identifier' &&
p.key.name === 'computed' &&
getStaticPropertyName(p) === 'computed' &&
p.value.type === 'ObjectExpression'
)
}
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/require-explicit-emits.js
Expand Up @@ -140,6 +140,20 @@ tester.run('require-explicit-emits', rule, {
</script>
`
},
// quoted
{
filename: 'test.vue',
code: `
<template>
<div @click="$emit('welcome')"/>
</template>
<script>
export default {
'emits': ['welcome']
}
</script>
`
},
// unknown
{
filename: 'test.vue',
Expand Down
17 changes: 17 additions & 0 deletions tests/lib/rules/return-in-computed-property.js
Expand Up @@ -394,6 +394,23 @@ ruleTester.run('return-in-computed-property', rule, {
line: 5
}
]
},
{
filename: 'test.vue',
code: `
export default {
'computed': {
foo() {
}
}
}`,
parserOptions,
errors: [
{
message: 'Expected to return a value in "foo" computed property.',
line: 4
}
]
}
]
})

0 comments on commit bbbb6ca

Please sign in to comment.