Skip to content

fix(core): track of default specifiers#9878

Merged
ematipico merged 2 commits intomainfrom
fix/import-tracking
Apr 9, 2026
Merged

fix(core): track of default specifiers#9878
ematipico merged 2 commits intomainfrom
fix/import-tracking

Conversation

@ematipico
Copy link
Copy Markdown
Member

Summary

Closes #9118

Test Plan

Added new tests

Docs

@ematipico ematipico requested review from a team April 9, 2026 09:50
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 9, 2026

🦋 Changeset detected

Latest commit: e5168c9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc 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

@github-actions github-actions Bot added A-Project Area: project A-Linter Area: linter A-Parser Area: parser L-JavaScript Language: JavaScript and super languages labels Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 53178 53178 0
Passed 51958 51958 0
Failed 1178 1178 0
Panics 42 42 0
Coverage 97.71% 97.71% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 38 38 0
Passed 37 37 0
Failed 1 1 0
Panics 0 0 0
Coverage 97.37% 97.37% 0.00%

markdown/commonmark

Test result main count This PR count Difference
Total 652 652 0
Passed 652 652 0
Failed 0 0 0
Panics 0 0 0
Coverage 100.00% 100.00% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5467 5467 0
Passed 1915 1915 0
Failed 3552 3552 0
Panics 0 0 0
Coverage 35.03% 35.03% 0.00%

ts/babel

Test result main count This PR count Difference
Total 640 640 0
Passed 569 569 0
Failed 71 71 0
Panics 0 0 0
Coverage 88.91% 88.91% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 18876 18876 0
Passed 13014 13014 0
Failed 5861 5861 0
Panics 1 1 0
Coverage 68.94% 68.94% 0.00%

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6443fd0c-e7c9-4e94-8a1b-3e8cdd0aa044

📥 Commits

Reviewing files that changed from the base of the PR and between 41daca2 and e5168c9.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/correctness/noUnusedImports/valid_issue_9118.astro.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (1)
  • crates/biome_js_syntax/src/import_ext.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_js_syntax/src/import_ext.rs

Walkthrough

Adds a changeset marking a patch for @biomejs/biome. Introduces AnyJsImportClause::default_specifiers to expose default import specifiers. Extends workspace embedded binding registration to record default import bindings. Adds test fixtures validating noUnusedImports behaviour for Svelte, Vue and Astro components so default imports used in templates are not reported as unused.

Suggested reviewers

  • dyc3
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly addresses the core change: tracking default specifiers in imports to fix false positives in the noUnusedImports rule.
Description check ✅ Passed The description references issue #9118 and indicates tests were added, which aligns with the changeset and test fixture additions.
Linked Issues check ✅ Passed The PR implements the required fix for issue #9118: tracking default specifiers in Svelte/Vue/Astro imports so they're no longer incorrectly flagged as unused.
Out of Scope Changes check ✅ Passed All changes directly support the stated objective: a syntax method addition, binding registration logic, test fixtures for Svelte/Vue/Astro, and a changeset documenting the patch.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/import-tracking

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/biome_service/src/workspace/document/services/embedded_bindings.rs (1)

116-124: Avoid dual paths for default import registration.

Line 116-124 already handles default imports generically; Line 126-134 re-handles default clauses again. It works, but it’s duplicate logic and easy to desynchronise later.

Suggested tidy-up
-        if let Some(default_specifiers) = clause.default_specifiers() {
-            let local_name = default_specifiers.local_name().ok()?;
+        if let Some(default_specifier) = clause.default_specifiers() {
+            let local_name = default_specifier.local_name().ok()?;
             let local_name = local_name.as_js_identifier_binding()?;
             let local_name = local_name.name_token().ok()?;
             self.js_bindings.insert(
                 local_name.text_trimmed_range(),
                 local_name.token_text_trimmed(),
             );
         }
-
-        // Handle default clause using accessors generated by the syntax crate.
-        if let Some(import) = clause.as_js_import_default_clause() {
-            let name = import.default_specifier().ok()?;
-            let name = name.local_name().ok()?;
-            let name = name.as_js_identifier_binding()?;
-            let name = name.name_token().ok()?;
-            self.js_bindings
-                .insert(name.text_trimmed_range(), name.token_text_trimmed());
-        }

One code path, one source of truth — future-you will thank present-you.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_service/src/workspace/document/services/embedded_bindings.rs`
around lines 116 - 124, The code currently registers default imports in two
places causing duplicated logic; keep the existing generic path that extracts
default_specifiers via clause.default_specifiers(), converts through
as_js_identifier_binding() and name_token(), and inserts into self.js_bindings
using text_trimmed_range() and token_text_trimmed(), and remove the redundant
second block that re-handles default clauses (the duplicate that performs the
same local_name extraction and self.js_bindings.insert). Consolidate any
remaining variant-specific logic into the single clause.default_specifiers()
path so there's one source of truth for default import registration.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/biome_service/src/workspace/document/services/embedded_bindings.rs`:
- Around line 116-124: The code currently registers default imports in two
places causing duplicated logic; keep the existing generic path that extracts
default_specifiers via clause.default_specifiers(), converts through
as_js_identifier_binding() and name_token(), and inserts into self.js_bindings
using text_trimmed_range() and token_text_trimmed(), and remove the redundant
second block that re-handles default clauses (the duplicate that performs the
same local_name extraction and self.js_bindings.insert). Consolidate any
remaining variant-specific logic into the single clause.default_specifiers()
path so there's one source of truth for default import registration.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 715e1ae5-983e-41f7-8295-91f7caabe6ac

📥 Commits

Reviewing files that changed from the base of the PR and between 78bce77 and 41daca2.

⛔ Files ignored due to path filters (3)
  • crates/biome_js_analyze/tests/specs/correctness/noUnusedImports/valid_issue_9118.astro.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/correctness/noUnusedImports/valid_issue_9118.svelte.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/correctness/noUnusedImports/valid_issue_9118.vue.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (6)
  • .changeset/funny-candles-shake.md
  • crates/biome_js_analyze/tests/specs/correctness/noUnusedImports/valid_issue_9118.astro
  • crates/biome_js_analyze/tests/specs/correctness/noUnusedImports/valid_issue_9118.svelte
  • crates/biome_js_analyze/tests/specs/correctness/noUnusedImports/valid_issue_9118.vue
  • crates/biome_js_syntax/src/import_ext.rs
  • crates/biome_service/src/workspace/document/services/embedded_bindings.rs

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 9, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 196 skipped benchmarks1


Comparing fix/import-tracking (e5168c9) with main (78bce77)

Open in CodSpeed

Footnotes

  1. 196 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@ematipico ematipico merged commit de6210f into main Apr 9, 2026
19 checks passed
@ematipico ematipico deleted the fix/import-tracking branch April 9, 2026 10:40
@github-actions github-actions Bot mentioned this pull request Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter A-Parser Area: parser A-Project Area: project L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 noUnusedImports wants to remove a used Svelte component import

2 participants