Skip to content
← Back to rules

vue/valid-define-options Correctness

What it does

Enforce valid defineOptions compiler macro.

Why is this bad?

defineOptions is a compiler macro for <script setup>. It must be called with a single object literal containing component options that are evaluable at compile time. Misuse such as referencing locally declared variables, declaring props/emits/expose/slots, calling without arguments, or passing type arguments cannot be processed by the compiler.

Examples

Examples of incorrect code for this rule:

vue
<script setup>
defineOptions(); // no options object
defineOptions({ name: "A" });
defineOptions({ name: "B" }); // multiple calls
defineOptions({ props: { msg: String } }); // use `defineProps()` instead
</script>

Examples of correct code for this rule:

vue
<script setup>
defineOptions({ name: "foo", inheritAttrs: false });
</script>

How to use

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

json
{
  "plugins": ["vue"],
  "rules": {
    "vue/valid-define-options": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["vue"],
  rules: {
    "vue/valid-define-options": "error",
  },
});
bash
oxlint --deny vue/valid-define-options --vue-plugin

Version

This rule was added in vnext.

References