Skip to content

fix: avoid false positives on import/export aliases#3

Merged
albertodeago merged 1 commit into
albertodeago:mainfrom
maroKanatani:fix/import-alias-false-positive
May 12, 2026
Merged

fix: avoid false positives on import/export aliases#3
albertodeago merged 1 commit into
albertodeago:mainfrom
maroKanatani:fix/import-alias-false-positive

Conversation

@maroKanatani

Copy link
Copy Markdown
Contributor

Fixes #2.

$expr as $type matches any use of the as token, including import
aliases (import { foo as bar }), namespace imports (import * as ns),
and export aliases (export { foo as bar }). The existing guard
! $expr <: within \import $_ from $_`` only handled single-specifier
imports and left the rest as false positives.

This was harmless until biome 2.4.9, which fixed metavariable matching
inside import { ... } / export { ... } clauses
(biomejs/biome#9586). After that fix the broken guard started firing.

The fix is to constrain on TsAsExpression() instead:

`$expr as $type` as $node where {
    $node <: TsAsExpression(),
    ! $type <: "const",
    register_diagnostic(span=$node, ...)
}

Added test fixtures for multi-specifier imports, namespace imports, and
export aliases. All existing tests still pass.

…iases

The previous pattern `$expr as $type` over-matches because the `as`
token appears in many AST constructs, not just `TsAsExpression`:
- `import { foo as bar } from ...` (JsNamedImportSpecifier)
- `import * as ns from ...` (JsNamespaceImportSpecifier)
- `export { foo as bar }` (JsExportNamedFromSpecifier)

The exclusion `! $expr <: within \`import $_ from $_\`` only
covered single-specifier default imports, leaving multi-specifier named
imports and namespace imports as false positives.

biome 2.4.9 fixed a metavariable matching bug
(biomejs/biome#9586) that previously masked the issue, so the false
positives now surface for any user of biome >= 2.4.9.

Constrain the matched node to `TsAsExpression()` so only genuine TS
type assertions are flagged.

Closes albertodeago#2
@maroKanatani

Copy link
Copy Markdown
Contributor Author

Hi @albertodeago — gentle ping on this one when you get a chance 🙏

This fixes a real regression that surfaces for any user on biome >= 2.4.9 (since biomejs/biome#9586 fixed the metavariable matching that was previously masking the issue). Happy to address any feedback if there's anything you'd like changed.

Thanks for maintaining this plugin!

@albertodeago

Copy link
Copy Markdown
Owner

hey @maroKanatani
sorry for not answering, I totally missed this PR
let me 👀 immediately and thanks for the contribution!

@albertodeago albertodeago left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Amazing work, thanks for the fix!

@albertodeago albertodeago merged commit 3f63e97 into albertodeago:main May 12, 2026
@maroKanatani maroKanatani deleted the fix/import-alias-false-positive branch May 12, 2026 13:35
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.

Using as in multi-specifier imports still gets flagged as false positive

2 participants