script/no-unused-emit-declarations
Flag declared events that are never emitted.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
opinionated, nuxt |
No | None |
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form.
Bad
defineEmits declares both change and unused, but the captured emit function only emits the literal event change.
<script setup lang="ts">
const emit = defineEmits(['change', 'unused'])
emit('change')
// `unused` is never emitted
</script>
Good
Removing unused makes the declared event list match the observed emission. The example uses a captured, unescaped emit binding so this local usage conclusion is available.
<script setup lang="ts">
const emit = defineEmits(['change'])
emit('change')
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"script/no-unused-emit-declarations": "warn"
}
},
});
Then run vp run lint.