Skip to content
← Back to rules

vue/return-in-emits-validator Correctness

What it does

Enforce that a return statement is present in emits validators (in Vue.js 3.0.0+).

Why is this bad?

An emits validator must return a boolean indicating whether the emitted payload is valid. Forgetting to return a value (or returning only falsy values) makes the validator effectively reject every emit, breaking the component contract silently.

Examples

Examples of incorrect code for this rule:

vue
<script>
export default {
  emits: {
    foo() {
      // missing return
    },
  },
};
</script>

Examples of correct code for this rule:

vue
<script>
export default {
  emits: {
    foo(payload) {
      return typeof payload === "string";
    },
  },
};
</script>

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["vue"],
  "rules": {
    "vue/return-in-emits-validator": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["vue"],
  rules: {
    "vue/return-in-emits-validator": "error",
  },
});
bash
oxlint --deny vue/return-in-emits-validator --vue-plugin

Version

This rule was added in vnext.

References