useVueDefineMacrosOrder
Este conteúdo não está disponível em sua língua ainda.
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/useVueDefineMacrosOrder
- This rule has an unsafe fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
- Same as
vue/define-macros-order
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useVueDefineMacrosOrder": "error" } } }}
Description
Section titled “Description”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).
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<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.
ℹ 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.
ℹ 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>
Options
Section titled “Options”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.
{ "linter": { "rules": { "nursery": { "useVueDefineMacrosOrder": { "options": { "order": [ "definePage", "defineProps", "defineEmits", "defineModel" ] } } } } }}
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.