Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
70912c6
feat(define-macros-order): add `allowTypesBetweenMacros` option
ValentinYoushkevich Aug 12, 2026
2bb3411
Merge branch 'master' into feat/define-macros-order-allow-types
ValentinYoushkevich Oct 19, 2026
654c403
Fix new eslint-plugin-unicorn lint issues
ValentinYoushkevich Oct 19, 2026
59ec5ba
Merge branch 'master' into feat/define-macros-order-allow-types
ValentinYoushkevich Oct 25, 2026
f8ed010
Merge remote-tracking branch 'upstream/master' into feat/define-macro…
ValentinYoushkevich Nov 9, 2026
0a58124
Merge remote-tracking branch 'upstream/master' into feat/define-macro…
ValentinYoushkevich Nov 14, 2026
139b47b
feat(define-macros-order): add `allowReferencedAbove` option
ValentinYoushkevich Nov 14, 2026
ae942a0
docs(define-macros-order): match the `allowReferencedAbove` examples …
ValentinYoushkevich Nov 16, 2026
af78b65
docs(define-macros-order): show referenced variables in the `allowRef…
ValentinYoushkevich Nov 16, 2026
87a1b22
fix(define-macros-order): mention referenced declarations in the erro…
ValentinYoushkevich Nov 16, 2026
b2c3001
fix(define-macros-order): only allow declarations above macros, and d…
ValentinYoushkevich Nov 16, 2026
a416acb
docs(define-macros-order): match `allowReferencedAbove` examples to t…
ValentinYoushkevich Nov 16, 2026
ce03f87
docs(define-macros-order): show a referenced enum in the example
ValentinYoushkevich Nov 22, 2026
b19f4d6
fix(define-macros-order): don't autofix when moving would reorder dep…
ValentinYoushkevich Nov 26, 2026
f55ee72
Merge remote-tracking branch 'upstream/master' into feat/define-macro…
ValentinYoushkevich Nov 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-melons-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-vue": minor
---

Added `allowReferencedAbove` option (default `true`) to `vue/define-macros-order` rule, which allows declarations that a macro references, directly or indirectly, to be placed right above it
64 changes: 63 additions & 1 deletion docs/rules/define-macros-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ This rule reports compiler macros (like `defineProps` or `defineEmits` but also
{
"vue/define-macros-order": ["error", {
"order": ["defineProps", "defineEmits"],
"defineExposeLast": false
"defineExposeLast": false,
"allowReferencedAbove": true
}]
}
```

- `order` (`string[]`) ... The order in which the macros should appear. The default is `["defineProps", "defineEmits"]`.
- `defineExposeLast` (`boolean`) ... Force `defineExpose` at the end.
- `allowReferencedAbove` (`boolean`) ... Allow declarations that a macro references to be placed right above it, below the previous macro. This includes types, interfaces, enums, `declare`d declarations, variables and functions, also when they are only referenced through other such declarations. Any other statement between the macros is still reported. The autofix moves the referenced declarations together with their macro, and doesn't fix the order if that would place a macro above a declaration it uses. Default is `true`.

### `{ "order": ["defineProps", "defineEmits"] }` (default)

Expand Down Expand Up @@ -181,6 +183,66 @@ const slots = defineSlots()

</eslint-code-block>

### `{ "allowReferencedAbove": true }` (default)

<eslint-code-block fix :rules="{'vue/define-macros-order': ['error', {order: ['defineModel', 'defineProps', 'defineEmits']}]}">

```vue
<!-- ✓ GOOD -->
<script setup lang="ts">
import { ref } from 'vue'

const lastValue = ref<string>()
const model = defineModel<string>({
get: (value) => lastValue.value ?? value
})

interface Item { id: number }
interface Props { items: Item[] }
defineProps<Props>()

type Foo = 'bar'
defineEmits<{ (e: Foo): void }>()
</script>
```

</eslint-code-block>

<eslint-code-block fix :rules="{'vue/define-macros-order': ['error', {order: ['defineModel', 'defineProps', 'defineEmits']}]}">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule definition doesn't match the heading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, both examples now use { allowReferencedAbove: true }. I dropped the defineModel part from them, since with the default order the rule doesn't check where defineModel is, so that part only worked with a custom order.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now the example doesn't show that variables are also allowed. It could look like only referenced types/interfaces are allowed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The section now uses exactly {allowReferencedAbove: true} from its heading, and the GOOD example shows a variable through a withDefaults default. The false section also got a GOOD example. While re-checking, I also fixed a false negative (an if or for with a var between macros was accepted) and stopped types from blocking the autofix; the description is updated accordingly.


```vue
<!-- ✗ BAD -->
<script setup lang="ts">
const model = defineModel<string>()

interface Props { foo: string }
console.log('unrelated')
defineProps<Props>()

type Unused = string
defineEmits(/* ... */)
</script>
```

</eslint-code-block>

### `{ "allowReferencedAbove": false }`

<eslint-code-block fix :rules="{'vue/define-macros-order': ['error', {allowReferencedAbove: false}]}">

```vue
<!-- ✗ BAD -->
<script setup lang="ts">
defineProps(/* ... */)

type Foo = 'bar'

defineEmits<{ (e: Foo): void }>()
</script>
```

</eslint-code-block>

## :rocket: Version

This rule was introduced in eslint-plugin-vue v8.7.0
Expand Down
Loading
Loading