script/return-in-emits-validator
Require a return value in every Vue emits validator.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
error |
essential, happy-path, ecosystem, nuxt, opinionated |
No | None |
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form.
Use a block-body arrow for the currently supported SFC filter. The underlying validator also handles method shorthand, but the current SFC prefilter does not reliably dispatch that shape.
Bad
The submit validator logs the payload but does not return a validation result, so its block body yields undefined.
<script lang="ts">
export default { emits: { submit: (payload: unknown) => { console.log(payload); } } };
</script>
Good
return payload != null supplies a boolean validation result for the submitted payload instead of ending without a returned value.
<script lang="ts">
export default { emits: { submit: (payload: unknown) => { return payload != null; } } };
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"script/return-in-emits-validator": "error"
}
},
});
Then run vp run lint.