Skip to content

Conversation

@kzhrk
Copy link
Contributor

@kzhrk kzhrk commented Nov 11, 2025

Closes #2940

Summary

Improves error messages for the vue/define-macros-order rule to distinguish between two distinct cases:

  1. macrosNotAtTop: When a macro comes after non-macro statements (e.g., console.log())
  2. macrosUnordered: When macros are not in the correct order relative to each other

Motivation

Previously, the rule always reported: "X should be the first statement in <script setup>", which was confusing when multiple macros were out of order.
Users couldn't easily understand whether they needed to move a macro to the top or reorder it relative to other macros.

With this improvement, users get more specific feedback:

  • "defineModel should be placed at the top of <script setup>" - when it's after a non-macro
  • "defineModel should be above defineEmits" - when it's in the wrong order with other macros

This makes it much clearer what action is needed to fix the issue.

Changes

  • Updated messages object with two new message types: macrosNotAtTop and macrosUnordered
  • Modified reportNotOnTop() function to detect whether the target statement is a macro from the order list
  • Uses macrosUnordered when the target is a macro, macrosNotAtTop otherwise
  • Updated all test expectations to match the new behavior (42 tests passing)

…dering errors (vuejs#2940)

Separate error messages for two distinct cases:
- macrosNotAtTop: when a macro comes after non-macro statements
- macrosUnordered: when macros are not in the correct order relative to each other

This provides clearer feedback to users about what needs to be fixed.
@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2025

🦋 Changeset detected

Latest commit: 41323da

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

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

Thanks! I only have one code style improvement suggestion.

Is this PR deliberately still in draft status?

@FloEdelmann FloEdelmann changed the title fix(define-macros-order): distinguish between macros placement and ordering errors (#2940) fix(define-macros-order): improve report messages Nov 11, 2025
@kzhrk
Copy link
Contributor Author

kzhrk commented Nov 11, 2025

@FloEdelmann

Is this PR deliberately still in draft status?

No, I was just waiting for the CI 😴
I'll check your suggestion.

@kzhrk kzhrk marked this pull request as ready for review November 11, 2025 15:16
Use array.find() instead of a for loop with break statement for a more
idiomatic and readable approach to finding the macro name.

Co-authored-by: Flo Edelmann <git@flo-edelmann.de>
@kzhrk kzhrk requested a review from FloEdelmann November 11, 2025 15:18
Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

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

Looks good to me now, thank you! 🙂

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves error messages for the vue/define-macros-order ESLint rule by introducing two distinct message types to better communicate the specific issue to users.

Key Changes:

  • Added two message types: macrosNotAtTop (when a macro comes after non-macro statements) and macrosUnordered (when macros are in the wrong order relative to each other)
  • Updated the reportNotOnTop() function to detect whether the target statement is a macro and select the appropriate message
  • Updated all 42 test cases to use the new message helper functions

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
lib/rules/define-macros-order.js Enhanced reportNotOnTop() function to detect whether the blocking statement is a macro and select appropriate error message; added macrosUnordered message definition
tests/lib/rules/define-macros-order.js Renamed message helper function from message() to notAtTopMessage(), added unorderedMessage() helper, and updated all test expectations to use the appropriate message for each scenario
.changeset/improve-define-macros-order-messages.md Added changeset documenting the improvement as a patch-level change

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@waynzh waynzh left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

@waynzh waynzh merged commit b47d479 into vuejs:master Nov 12, 2025
21 checks passed
@github-actions github-actions bot mentioned this pull request Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vue/define-macros-order confusing error message

3 participants