fix(define-macros-order): improve report messages#2953
Conversation
…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 detectedLatest commit: 41323da The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
No, I was just waiting for the CI 😴 |
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>
FloEdelmann
left a comment
There was a problem hiding this comment.
Looks good to me now, thank you! 🙂
There was a problem hiding this comment.
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) andmacrosUnordered(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.
Closes #2940
Summary
Improves error messages for the
vue/define-macros-orderrule to distinguish between two distinct cases:console.log())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:
<script setup>" - when it's after a non-macroThis makes it much clearer what action is needed to fix the issue.
Changes
macrosNotAtTopandmacrosUnorderedreportNotOnTop()function to detect whether the target statement is a macro from the order listmacrosUnorderedwhen the target is a macro,macrosNotAtTopotherwise