Skip to content

fix(core): update snippet via fix all#9863

Merged
ematipico merged 2 commits intomainfrom
fix/embedded-fixall
Apr 8, 2026
Merged

fix(core): update snippet via fix all#9863
ematipico merged 2 commits intomainfrom
fix/embedded-fixall

Conversation

@ematipico
Copy link
Copy Markdown
Member

Summary

Closes #9690

I knew the bug was around the update snippet, but I wasn't able to track it down. Used the AI agent to understand where the culprit was.

In the process, I also updated the biome skill; the comments they emit are pure jargon if left unchecked.

Test Plan

Added new tests

Docs

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 8, 2026

🦋 Changeset detected

Latest commit: 7a371d4

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-CLI Area: CLI A-Project Area: project labels Apr 8, 2026
@ematipico ematipico force-pushed the fix/embedded-fixall branch from 39212fe to ab3ad6a Compare April 8, 2026 17:19
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 8, 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: 2effb0e7-05fa-45a9-afe1-9ab64438b006

📥 Commits

Reviewing files that changed from the base of the PR and between ab3ad6a and 7a371d4.

📒 Files selected for processing (1)
  • crates/biome_grit_patterns/src/grit_target_language/js_target_language/generated_mappings.rs

Walkthrough

This change makes biome check --write idempotent for HTML files with embedded <style>/<script> blocks by re-indenting embedded formatter output to match the host HTML before splicing it back. It adds helper functions to extract and apply host indentation, updates update_snippets to use the re-indentation, adds unit tests for indent handling, and adds an integration test exercising check --write on an HTML file. Also updates a docs skill file and adds a native slot mapping for JsxShorthandAttribute.

Possibly related PRs

Suggested labels

A-Formatter, L-HTML

Suggested reviewers

  • siketyan
  • dyc3
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately summarises the main fix: addressing the snippet update logic that caused biome check --write idempotency issues.
Description check ✅ Passed Description clearly relates to the changeset, referencing the specific linked issue #9690 and explaining the fix approach plus skill documentation updates.
Linked Issues check ✅ Passed All code changes directly address issue #9690: the HTML file handler now re-indents embedded formatter output to achieve idempotence, and tests verify the fix works.
Out of Scope Changes check ✅ Passed Changes are tightly scoped: HTML snippet re-indentation logic, integration test, skill documentation update, and a single Grit pattern mapping entry. All relate to the stated objectives.

✏️ 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/embedded-fixall

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

@ematipico ematipico requested review from a team April 8, 2026 17:21
@github-actions github-actions Bot added the L-Grit Language: GritQL label Apr 8, 2026
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.

Caution

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

⚠️ Outside diff range comments (1)
crates/biome_service/src/file_handlers/html.rs (1)

1831-1841: ⚠️ Potential issue | 🟠 Major

Handle all-whitespace tokens to avoid trivia duplication and non-idempotent rewrites.

If value is only whitespace, both read_leading_trivia and read_trailing_trivia can return the full string. That means the reconstructed token can duplicate whitespace (and drift across runs), which is the same class of idempotency bug this PR is fixing.

🩹 Proposed fix
 fn read_trailing_trivia(value: &str) -> Cow<'_, str> {
     let bytes = value.as_bytes();
+    let leading_count = bytes
+        .iter()
+        .take_while(|&&b| matches!(b, b' ' | b'\t' | b'\n' | b'\r'))
+        .count();
+
+    if leading_count == value.len() {
+        return Cow::Borrowed("");
+    }
+
     let count = bytes
         .iter()
         .rev()
         .take_while(|&&b| matches!(b, b' ' | b'\t' | b'\n' | b'\r'))
         .count();

     if count > 0 {
         Cow::Borrowed(&value[value.len() - count..])
     } else {
         Cow::Borrowed("")
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_service/src/file_handlers/html.rs` around lines 1831 - 1841,
read_trailing_trivia currently returns the full string when the input is all
whitespace, which can duplicate whitespace with read_leading_trivia; update
read_trailing_trivia so that if count == value.len() (i.e., the string is all
whitespace) it returns an empty trivia (e.g., Cow::Borrowed("") ) instead of the
whole value, ensuring only one of read_leading_trivia/read_trailing_trivia
yields the full whitespace and preventing duplicated/non-idempotent rewrites.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@crates/biome_service/src/file_handlers/html.rs`:
- Around line 1831-1841: read_trailing_trivia currently returns the full string
when the input is all whitespace, which can duplicate whitespace with
read_leading_trivia; update read_trailing_trivia so that if count == value.len()
(i.e., the string is all whitespace) it returns an empty trivia (e.g.,
Cow::Borrowed("") ) instead of the whole value, ensuring only one of
read_leading_trivia/read_trailing_trivia yields the full whitespace and
preventing duplicated/non-idempotent rewrites.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f1c6df5f-d04f-4ff7-93de-e2cb29b66c03

📥 Commits

Reviewing files that changed from the base of the PR and between 9342fe1 and ab3ad6a.

⛔ Files ignored due to path filters (1)
  • crates/biome_cli/tests/snapshots/main_cases_html/check_write_html_with_embedded_style_is_idempotent.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (4)
  • .changeset/wise-aliens-draw.md
  • .claude/skills/biome-developer/SKILL.md
  • crates/biome_cli/tests/cases/html.rs
  • crates/biome_service/src/file_handlers/html.rs

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 8, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks
⏩ 247 skipped benchmarks1


Comparing fix/embedded-fixall (7a371d4) with main (9342fe1)

Open in CodSpeed

Footnotes

  1. 247 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 6a44619 into main Apr 8, 2026
16 checks passed
@ematipico ematipico deleted the fix/embedded-fixall branch April 8, 2026 18:38
@github-actions github-actions Bot mentioned this pull request Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Project Area: project L-Grit Language: GritQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [BUG]: biome check --write falsely reports "Fixed 1 file" on every run for a HTML file

2 participants