Skip to content

fix(embeds): track attributes text expressions#9526

Merged
ematipico merged 2 commits intomainfrom
fix/svelte-use-import-type
Mar 17, 2026
Merged

fix(embeds): track attributes text expressions#9526
ematipico merged 2 commits intomainfrom
fix/svelte-use-import-type

Conversation

@ematipico
Copy link
Copy Markdown
Member

@ematipico ematipico commented Mar 17, 2026

Summary

Closes #9358
Closes #9375

I used AI to detect the issue.

Test Plan

Added a test

Docs

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 17, 2026

🦋 Changeset detected

Latest commit: cea0b22

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 L-JavaScript Language: JavaScript and super languages labels Mar 17, 2026
@ematipico ematipico force-pushed the fix/svelte-use-import-type branch from 32beab6 to bda1ac8 Compare March 17, 2026 16:53
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 17, 2026

Walkthrough

This PR fixes tracking of attribute expressions with text values in Svelte files. The changes extend the HTML file handler to parse and embed text-expression initializers in HTML attributes (e.g., class={buttonClass()}) during Svelte processing, allowing the analyser to recognise runtime usage of imported functions. Associated test utilities are updated to disable default module resolution and project scanning, and new test cases are added to validate the fix for issues #9358 and #9375.

Possibly related PRs

Suggested labels

A-Parser

Suggested reviewers

  • dyc3
  • siketyan
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: fixing tracking of attribute text expressions in embedded/Svelte contexts.
Description check ✅ Passed The description references the linked issues (#9358, #9375) directly and discloses AI assistance, providing context for the fix.
Linked Issues check ✅ Passed The code changes address both linked issues: html.rs adds tracking for Svelte attribute text expressions [#9358], and the test file validates the fix handles runtime usage detection [#9358, #9375].
Out of Scope Changes check ✅ Passed All changes are in-scope: core fix in html.rs, test file with reproduction case, changeset entry, and test utilities for HTML-ish file handling—nothing extraneous detected.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/svelte-use-import-type
📝 Coding Plan
  • Generate coding plan for human review comments

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

Tip

CodeRabbit can use OpenGrep to find security vulnerabilities and bugs across 17+ programming languages.

OpenGrep is compatible with Semgrep configurations. Add an opengrep.yml or semgrep.yml configuration file to your project to enable OpenGrep analysis.

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.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/biome_test_utils/src/lib.rs (1)

901-912: ⚠️ Potential issue | 🟠 Major

This de-scopes module-graph coverage for all HTML-ish tests.

analyze_with_workspace() still mirrors sibling sources into the in-memory FS for module-graph rules, but ModuleGraphResolutionKind::None means that context is never resolved here. Together with ScanKind::NoScanner, this helper no longer exercises the same project context as the non-workspace path. I’d only disable these knobs when the selected rule does not need the graph, mirroring NeedsModuleGraph in crates/biome_js_analyze/tests/spec_tests.rs.

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

In `@crates/biome_test_utils/src/lib.rs` around lines 901 - 912, The test helper
analyze_with_workspace currently forces ModuleGraphResolutionKind::None and
ScanKind::NoScanner which disables module-graph resolution for all HTML-ish
tests; change it to only disable those when the selected rule does not require a
module graph (mirror the NeedsModuleGraph check used in
crates/biome_js_analyze/tests/spec_tests.rs). In practice, update
analyze_with_workspace() to inspect the rule metadata (or accept a flag) and set
module_graph_resolution_kind to the normal resolution mode and scan_kind to the
real scanner unless the rule indicates it does not need the module graph (i.e.,
when NeedsModuleGraph is false), otherwise keep ModuleGraphResolutionKind::None
and ScanKind::NoScanner.
🧹 Nitpick comments (1)
crates/biome_js_analyze/tests/specs/style/useImportType/valid-issue-9358.svelte (1)

1-7: Nice regression; please add the event-handler twin too.

This covers class={...}, but the PR also closes the unused-handler case. A sibling fixture with <svelte:window onscroll={handleScroll} /> would keep #9375 from sneaking back in.

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

In
`@crates/biome_js_analyze/tests/specs/style/useImportType/valid-issue-9358.svelte`
around lines 1 - 7, Add a sibling test fixture that mirrors the existing
class-binding case but for event handlers to cover the unused-handler
regression: create a new .svelte test file next to valid-issue-9358.svelte that
defines a handleScroll function (e.g. function handleScroll() {}) and uses it in
a top-level window handler like <svelte:window onscroll={handleScroll} /> (and
include any minimal markup/ts script similar to the original fixture), ensuring
the file name indicates it’s the event-handler twin so the test runner picks it
up.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.changeset/poor-spies-switch.md:
- Line 5: Update the changeset .changeset/poor-spies-switch.md to use the repo
changeset format and a user-facing lead: replace the implementation-style
sentence with a bug-fix entry that starts "Fixed
[`#9358`](https://github.com/biomejs/biome/issues/9358) and
[`#9375`](https://github.com/biomejs/biome/issues/9375): ..." and then a concise
user-visible description such as "Svelte template references (e.g.,
class={buttonClass()}) are no longer misclassified as type-only or unused, so
attributes with text expressions are tracked correctly in Svelte files." Ensure
the file follows the project’s changeset/body formatting (leading Fixed
[`#NUMBER`]: ... line and a short explanatory sentence).

In `@crates/biome_js_analyze/tests/spec_tests.rs`:
- Line 96: Remove the stray debug print statement dbg!("Running HTML-ish test
{input_file:?}"); from the HTML-ish spec test so it no longer writes to stderr
during every test run; locate the invocation in the spec_tests.rs test function
and either delete the dbg! call or replace it with a non-verbose logger call
(e.g., a trace/debug via the test harness logger) if you need retained
diagnostics.

In
`@crates/biome_service/src/workspace/document/services/embedded_value_references.rs`:
- Line 56: Remove the stray dbg!(&self.references) call that prints every
reference to stderr; locate the occurrence of dbg!(&self.references) in
embedded_value_references.rs (inside the implementation that owns
self.references) and delete it or replace it with a non-allocating logging call
such as debug!(target: "embedded_value_references", "references = {:?}",
self.references) or trace!(...) if you need the information only for debugging,
ensuring you import and use the project's logging/tracing facade instead of
dbg!.

---

Outside diff comments:
In `@crates/biome_test_utils/src/lib.rs`:
- Around line 901-912: The test helper analyze_with_workspace currently forces
ModuleGraphResolutionKind::None and ScanKind::NoScanner which disables
module-graph resolution for all HTML-ish tests; change it to only disable those
when the selected rule does not require a module graph (mirror the
NeedsModuleGraph check used in crates/biome_js_analyze/tests/spec_tests.rs). In
practice, update analyze_with_workspace() to inspect the rule metadata (or
accept a flag) and set module_graph_resolution_kind to the normal resolution
mode and scan_kind to the real scanner unless the rule indicates it does not
need the module graph (i.e., when NeedsModuleGraph is false), otherwise keep
ModuleGraphResolutionKind::None and ScanKind::NoScanner.

---

Nitpick comments:
In
`@crates/biome_js_analyze/tests/specs/style/useImportType/valid-issue-9358.svelte`:
- Around line 1-7: Add a sibling test fixture that mirrors the existing
class-binding case but for event handlers to cover the unused-handler
regression: create a new .svelte test file next to valid-issue-9358.svelte that
defines a handleScroll function (e.g. function handleScroll() {}) and uses it in
a top-level window handler like <svelte:window onscroll={handleScroll} /> (and
include any minimal markup/ts script similar to the original fixture), ensuring
the file name indicates it’s the event-handler twin so the test runner picks it
up.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0b14ccbf-8f97-4066-83b3-62e1565577a0

📥 Commits

Reviewing files that changed from the base of the PR and between bc709f6 and bda1ac8.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/style/useImportType/valid-issue-9358.svelte.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (6)
  • .changeset/poor-spies-switch.md
  • crates/biome_js_analyze/tests/spec_tests.rs
  • crates/biome_js_analyze/tests/specs/style/useImportType/valid-issue-9358.svelte
  • crates/biome_service/src/file_handlers/html.rs
  • crates/biome_service/src/workspace/document/services/embedded_value_references.rs
  • crates/biome_test_utils/src/lib.rs

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 17, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 156 skipped benchmarks1


Comparing fix/svelte-use-import-type (bda1ac8) with main (61f53ee)2

Open in CodSpeed

Footnotes

  1. 156 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.

  2. No successful run was found on main (bc709f6) during the generation of this report, so 61f53ee was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@ematipico ematipico requested review from a team March 17, 2026 17:20
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These changes feel unrelated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They are a tangent. When testing a file, the infrastructure scans all files. It could cause side effects

@ematipico ematipico merged commit 4d42823 into main Mar 17, 2026
13 checks passed
@ematipico ematipico deleted the fix/svelte-use-import-type branch March 17, 2026 21:53
@github-actions github-actions bot mentioned this pull request Mar 17, 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-Project Area: project L-JavaScript Language: JavaScript and super languages

Projects

None yet

2 participants