feat(no-import-compiler-macros): clarify that macros are not allowed outside <script setup> - #2938
Conversation
🦋 Changeset detectedLatest commit: b4e550c 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 |
<script setup><script setup>
FloEdelmann
left a comment
There was a problem hiding this comment.
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?
That was my guess too. But they can be wrongly imported by the user. Updated the tests 👍 |
But the Do you agree? If so, feel free to update the PR to only improve test coverage for the non- |
|
I would prefer an own error/diagnostic message for using compiler macros outside Vue files. |
waiting for the PR result of vuejs/eslint-plugin-vue#2938 related #11440 https://eslint.vuejs.org/rules/no-import-compiler-macros
|
Changing the message based on whether the import occurs inside |
<script setup><script setup>
…-only-in-`<script-setup>`
FloEdelmann
left a comment
There was a problem hiding this comment.
Thanks, looks good to me now 🙂
There was a problem hiding this comment.
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
onlyValidInScriptSetupfor 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.
<script setup><script setup>
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>.