Skip to content

Conversation

@Sysix
Copy link
Contributor

@Sysix Sysix commented Oct 4, 2025

After reading #2437, I found out that the compiler warnings are only reported at <script setup>:
https://github.com/vuejs/core/blob/c16f8a94c7eda79f51f44b7b3c64c72343df0d38/packages/compiler-sfc/src/compileScript.ts#L321-L355

Changed the rule to report another message when macros are found outside <script setup>.

@changeset-bot
Copy link

changeset-bot bot commented Oct 4, 2025

🦋 Changeset detected

Latest commit: b4e550c

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 Minor

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

@Sysix Sysix changed the title refactor(no-import-compiler-macros): check only in <script setup> fix(no-import-compiler-macros): check only in <script setup> Oct 4, 2025
@Sysix Sysix marked this pull request as ready for review October 4, 2025 15:44
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.

It's true that Vue emits the runtime warning only in <script setup>, but I think that is because the compiler macros are only available in <script setup>. So while it would be more correct for the ESLint rule to only report compiler macro imports in <script setup>, it would not really make sense to import them outside <script setup>, too, would it?

@Sysix
Copy link
Contributor Author

Sysix commented Oct 6, 2025

it would not really make sense to import them outside <script setup>, too, would it?

That was my guess too. But they can be wrongly imported by the user.
Do not know what the bundler/vue-compiler will do. Maybe a new ESLint rule like no-compilier-macros-outside-script-setup?

Updated the tests 👍

@FloEdelmann
Copy link
Member

But they can be wrongly imported by the user.

But the vue/no-import-compiler-macros already warns about that case, while this PR removes exactly this warning. So I think the current behavior is better.

Do you agree? If so, feel free to update the PR to only improve test coverage for the non-<script setup> case. Otherwise, I'm open for discussion 🙂

@Sysix
Copy link
Contributor Author

Sysix commented Oct 6, 2025

I would prefer an own error/diagnostic message for using compiler macros outside Vue files.
Do you think it is okay to include it in this rule?
Something like

'{{name}} is a compiler macro and is only valid inside `<script>`with "setup".

@FloEdelmann
Copy link
Member

Changing the message based on whether the import occurs inside <script setup> or not seems like a good improvement to me 🙂 👍

@Sysix Sysix marked this pull request as draft October 14, 2025 20:36
@Sysix Sysix changed the title fix(no-import-compiler-macros): check only in <script setup> fix(no-import-compiler-macros): make it clear that macros are not allowed outside <script setup> Oct 31, 2025
@Sysix Sysix marked this pull request as ready for review October 31, 2025 15:15
@Sysix Sysix requested a review from FloEdelmann October 31, 2025 15:15
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, looks good to me now 🙂

@FloEdelmann FloEdelmann requested a review from Copilot October 31, 2025 15:48
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 updates the vue/no-import-compiler-macros rule to provide a clearer error message when compiler macros are imported outside of <script setup> blocks. Instead of saying macros "don't need to be imported" (which could be confusing when not in <script setup>), the new message clarifies that these macros "can only be used inside <script setup>".

Key changes:

  • Added a new error message onlyValidInScriptSetup for contexts outside <script setup>
  • Updated the rule logic to use utils.isScriptSetup() to determine which message to display
  • Added test coverage for non-<script setup> scenarios (regular <script> blocks and TypeScript files)

Reviewed Changes

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

File Description
lib/rules/no-import-compiler-macros.js Imports utils module, adds new error message, and conditionally selects the appropriate message based on script context
tests/lib/rules/no-import-compiler-macros.js Adds test cases for compiler macro imports in non-setup contexts (regular script and .ts file)
.changeset/lemon-socks-follow.md Documents the change as a minor version bump with a description of the improvement

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

@FloEdelmann FloEdelmann merged commit 5ec36ce into vuejs:master Oct 31, 2025
21 checks passed
@FloEdelmann FloEdelmann changed the title fix(no-import-compiler-macros): make it clear that macros are not allowed outside <script setup> feat(no-import-compiler-macros): clarify that macros are not allowed outside <script setup> Oct 31, 2025
@github-actions github-actions bot mentioned this pull request Oct 30, 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.

2 participants