Skip to content

useVueDefineMacrosOrder

biome.json
{
"linter": {
"rules": {
"nursery": {
"useVueDefineMacrosOrder": "error"
}
}
}
}

Enforce specific order of Vue compiler macros.

This rule ensures consistent ordering of Vue’s Composition API compiler macros in <script setup> blocks. Enforcing a consistent order improves code readability and maintainability by establishing a predictable structure.

These macros must also appear before any other statements (except imports, type declarations, and debugger statements).

<script lang="ts" setup>
const emit = defineEmits(['update'])
const props = defineProps<{ name: string }>()
</script>
code-block.vue:2:7 lint/nursery/useVueDefineMacrosOrder  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

defineProps macro is out of order.

1 │ const emit = defineEmits([‘update’])
> 2 │ const props = defineProps<{ name: string }>()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 │

Macros defined in <script setup> should be ordered as follows: defineModel, defineProps, defineEmits

and be placed before any non-macro statements, except for type declarations, imports, exports or debugger statements.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Reorder macro defineProps.

1 - const·emit·=·defineEmits([update])
2 - const·props·=·defineProps<{·name:·string·}>()
1+ const·props·=·defineProps<{·name:·string·}>()
2+ const·emit·=·defineEmits([update])
3 3

<script lang="ts" setup>
import { ref } from 'vue'
const count = ref(0)
const props = defineProps<{ name: string }>()
</script>
code-block.vue:4:7 lint/nursery/useVueDefineMacrosOrder  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

defineProps macro is out of order.

3 │ const count = ref(0)
> 4 │ const props = defineProps<{ name: string }>()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 │

Macros defined in <script setup> should be ordered as follows: defineModel, defineProps, defineEmits

and be placed before any non-macro statements, except for type declarations, imports, exports or debugger statements.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Reorder macro defineProps.

1 1 import { ref } from ‘vue’
2 -
3 - const·count·=·ref(0)
4 - const·props·=·defineProps<{·name:·string·}>()
2+ const·props·=·defineProps<{·name:·string·}>()
3+
4+
5+ const·count·=·ref(0)
5 6

<script lang="ts" setup>
const props = defineProps<{ name: string }>()
const emit = defineEmits(['update'])
</script>
<script lang="ts" setup>
import { ref } from 'vue'
const model = defineModel()
const props = defineProps<{ name: string }>()
const emit = defineEmits(['update'])
const count = ref(0)
</script>
<script lang="ts" setup>
import { ref } from 'vue'
interface Props {
value: string
}
const props = defineProps<Props>()
const emit = defineEmits(['update'])
</script>

Allows specifying the order in which the Vue compiler macros should appear.

Default: ["defineModel", "defineProps", "defineEmits"]

This is not limited to built-in macros, for example unplug-vue-router definePage can be listed here as well.

biome.json
{
"linter": {
"rules": {
"nursery": {
"useVueDefineMacrosOrder": {
"options": {
"order": [
"definePage",
"defineProps",
"defineEmits",
"defineModel"
]
}
}
}
}
}
}