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 only look inside <script setup> and not other files like someMacro.ts.

Copied the logic from

create(context) {
const scriptSetup = utils.getScriptSetupElement(context)
if (!scriptSetup) {
return {}
}
/** @type {Set<Expression | SpreadElement>} */
const emitsDefExpressions = new Set()
let hasDefaultExport = false
/** @type {CallExpression[]} */
const defineEmitsNodes = []
/** @type {CallExpression | null} */
let emptyDefineEmits = null
return utils.compositingVisitors(
utils.defineScriptSetupVisitor(context, {

Copy link

changeset-bot bot commented Oct 4, 2025

🦋 Changeset detected

Latest commit: f1e1ddb

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

@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".

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