eslint-plugin-vue
eslint-plugin-vue copied to clipboard
Allow emits in vue/no-unused-properties rule
I've already check open propositions and there no such suggestion
What rule do you want to change? -> vue/no-unused-properties
Does this change cause the rule to produce more or fewer warnings? -> more warnings
How will the change be implemented? (New option, new default behavior, etc.)? -> Would be nice to add 'emits' group into this rule.
Please provide some example code that this change will affect:
<!-- ✓ GOOD -->
<template>
<div></div>
</template>
<script>
export default {
emits: ['count'],
methods: {
setCount () {
this.$emit('count', newCount)
}
}
}
</script>
<!-- ✗ BAD (`count` property not used) -->
<template>
<div></div>
</template>
<script>
export default {
emits: ['count'],
}
</script>
What does the rule currently do for this code? -> nothing with emits
What will the rule do after it's changed? -> It will detect unused emits declaration
I don't think it should be part of the vue/no-unused-properties
rule, because emitting an event is not the same as using a property/variable.
But I do like the suggested rule. Maybe it should rather be part of the vue/require-explicit-emits
rule, maybe with an option reportUnusedEmitDeclarations
?
Or it could be a new rule vue/no-unused-emit-declarations
(or similar).
I think it makes sense to create a new rule 👍
Hello @ota-meshi @FloEdelmann
Is it possible to handle the following cases in the proposed rule?
1
<script>
const allEmits = ['foo', 'bar'];
export default {
emits: allEmits,
})
</script>
2
<script>
const sharedEmits = ['foo', 'bar'];
export default {
emits: [...sharedEmits, 'baz'],
})
</script>
3
<script>
import sharedEmits from 'sharedEmits';
export default {
emits: [...sharedEmits, 'baz'],
})
</script>
4
<script>
const allEmits = {
foo: 'foo',
bar: 'bar',
}
export default {
emits: Object.values(allEmits),
})
</script>
@ItMaga Probably all of them are too much effort at the moment. I'd start with only checking events that are defined in the emits
section (or defineEmits
). Later, those special cases could be added, but let's keep the scope small for now.
Hello,
What's the status of this rule? The idea is still to implement it?
Thanks in advance!
Currently, as far as I know, nobody is actively working on it. But since the issue is still open and has the accepted proposition
label, it is open for submissions. If anyone would like to work on this, feel free to submit a PR!