Skip to content

Commit

Permalink
fix(no-unused-emit-declarations): error in render functions (#2388)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntnyq committed Jan 31, 2024
1 parent ac73565 commit b7ccbbd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rules/no-unused-emit-declarations.js
Expand Up @@ -63,6 +63,7 @@ function hasReferenceId(value, setupContext) {
* @returns {boolean}
*/
function isEmitVariableName(name, emitReferenceIds) {
if (emitReferenceIds.size === 0) return false
const emitVariable = emitReferenceIds.values().next().value.name
return emitVariable === name
}
Expand Down
34 changes: 34 additions & 0 deletions tests/lib/rules/no-unused-emit-declarations.js
Expand Up @@ -369,6 +369,19 @@ tester.run('no-unused-emit-declarations', rule, {
const m = defineModel('foo')
</script>
`
},
{
filename: 'test.vue',
code: `
<script>
export default {
emits: ['foo'],
setup(_, ctx) {
return () => h('button', { onClick: () => ctx.emit('foo') })
}
}
</script>
`
}
],
invalid: [
Expand Down Expand Up @@ -750,6 +763,27 @@ tester.run('no-unused-emit-declarations', rule, {
line: 3
}
]
},
{
filename: 'test.vue',
code: `
<script>
export default {
emits: ['foo'],
setup(_, ctx) {
return () => h('button')
}
}
</script>
`,
errors: [
{
messageId: 'unused',
line: 4,
column: 19,
endColumn: 24
}
]
}
]
})

0 comments on commit b7ccbbd

Please sign in to comment.