Vize

script/require-explicit-emits

Require emitted events to be declared in defineEmits or the emits option

Bad · Good

Default severity: warning
Presets: none
Automatic fix: None; review the suggested change
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form
Options: No rule-specific options. Severity and preset selection are configurable.

Configuration (Vite+)

import { defineConfig } from "@vizejs/vite-plugin/vite-plus";

export default defineConfig({
  lint: {
    vize: {
      "preset": "incremental",
      "rules": {
        "script/require-explicit-emits": "warn"
      }
    },
  },
});
vp run lint

Bad

The captured emit function emits save, but defineEmits([]) declares no such event.

<script setup lang="ts">
const emit = defineEmits([]);
emit("save");
</script>

Good

Adding "save" to the declaration makes the emitted literal event part of the component’s explicit event contract.

<script setup lang="ts">
const emit = defineEmits(["save"]);
emit("save");
</script>

Good avoids this rule's finding under the configuration above; other rules may still report diagnostics.

Implementation · All rules