Vize

script/define-macros-order

Enforce a consistent order of the Vue compiler macros in <script setup>

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/define-macros-order": "warn"
      }
    },
  },
});
vp run lint

Bad

defineProps appears before defineModel, although defineModel has the earlier rank in the canonical macro order.

<script setup lang="ts">
// defineProps before defineModel (out of canonical order)
const props = defineProps<{ count: number }>()
const model = defineModel<string>()
</script>

Good

The declarations follow the exact sequence defineOptions, defineModel, defineProps, defineEmits, defineSlots, before unrelated runtime statements.

<script setup lang="ts">
defineOptions({ name: 'MyComponent' })
const model = defineModel<string>()
const props = defineProps<{ count: number }>()
const emit = defineEmits<{ change: [value: string] }>()
defineSlots<{ default(props: {}): any }>()
</script>

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

Implementation · All rules