Skip to content

useVueDefineMacrosOrder (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"style": {
"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:3:7 lint/style/useVueDefineMacrosOrder  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ defineProps macro is out of order.

1 │ <script lang="ts" setup>
2 │ const emit = defineEmits(['update'])
> 3 │ const props = defineProps<{ name: string }>()
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 │ </script>
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.

ℹ Unsafe fix: Reorder macro defineProps.

1 1 │ <script lang="ts" setup>
2 │ - const·emit·=·defineEmits(['update'])
3 │ - const·props·=·defineProps<{·name:·string·}>()
2 │ + const·props·=·defineProps<{·name:·string·}>()
3 │ +
4 │ + const·emit·=·defineEmits(['update'])
4 5 │ </script>
5 6 │

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

ℹ defineProps macro is out of order.

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

ℹ 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.

ℹ Unsafe fix: Reorder macro defineProps.

1 1 │ <script lang="ts" setup>
2 2 │ import { ref } from 'vue'
3 │ -
4 │ - const·count·=·ref(0)
5 │ - const·props·=·defineProps<{·name:·string·}>()
3 │ + const·props·=·defineProps<{·name:·string·}>()
4 │ +
5 │ +
6 │ + const·count·=·ref(0)
6 7 │ </script>
7 8 │

<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": {
"style": {
"useVueDefineMacrosOrder": {
"level": "on",
"options": {
"order": [
"definePage",
"defineProps",
"defineEmits",
"defineModel"
]
}
}
}
}
}
}