Skip to content

fix(core): idempotence formatting html-ish files#9532

Merged
ematipico merged 1 commit intomainfrom
fix/idempotency-formatting
Mar 17, 2026
Merged

fix(core): idempotence formatting html-ish files#9532
ematipico merged 1 commit intomainfrom
fix/idempotency-formatting

Conversation

@ematipico
Copy link
Copy Markdown
Member

Summary

Closes #9117

The issue was caused by the loss of indentation when fixing embedded snippets. The fix adds a new parameter passed to fix_all, which is the indentation required. It's passed when calling fix_all of the embeds.

Test Plan

Added new tests

Docs

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 17, 2026

🦋 Changeset detected

Latest commit: d6f9bcb

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 Mar 17, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 17, 2026

Walkthrough

This PR fixes a false-positive change detection issue where biome check --write incorrectly reported Svelte/Vue files as modified when html.formatter.indentScriptAndStyle was enabled and the files were already properly formatted. The fix introduces an embeds_initial_indent field to FixAllParams and updates the ProcessFixAll::finish method signature to accept an initial_indent parameter. File handlers for Svelte and Vue now set this value when indentation is enabled, and the formatter uses print_with_indent to preserve indentation during formatting. Tests validate idempotence for both frameworks.

Possibly related PRs

Suggested labels

A-Core, A-Formatter, A-CLI, L-HTML

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 fix: ensuring idempotent formatting for HTML-like files (Svelte/Vue) when indentScriptAndStyle is enabled, which directly addresses the issue.
Description check ✅ Passed The description is related to the changeset—it references issue #9117, explains the root cause (indentation loss), and describes the solution (new parameter for indentation).
Linked Issues check ✅ Passed The PR directly addresses issue #9117 by fixing the non-idempotent formatting problem through preserving indentation for embedded snippets, and includes comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes are narrowly focused on fixing the indentation preservation issue for embedded snippets across relevant file handlers, with no unrelated modifications 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/idempotency-formatting
📝 Coding Plan
  • Generate coding plan for human review comments

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_cli/tests/cases/indent_script_and_style.rs (1)

113-117: Consider adding a <style> idempotence fixture as well.

Current additions cover script indentation; a style-block case would close the loop on indentScriptAndStyle.

Also applies to: 151-152

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

In `@crates/biome_cli/tests/cases/indent_script_and_style.rs` around lines 113 -
117, Add a second idempotence fixture alongside SVELTE_FILE_ALREADY_FORMATTED
that contains a <style> block already formatted with the expected
indentScriptAndStyle indentation so the test covers both <script> and <style>
idempotence; update the test constant name(s) in
crates/biome_cli/tests/cases/indent_script_and_style.rs (e.g.,
SVELTE_FILE_ALREADY_FORMATTED and the similar constant at lines ~151-152) and
ensure the test uses the new <style> fixture when invoking the
indentScriptAndStyle behavior.
🤖 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_cli/tests/cases/indent_script_and_style.rs`:
- Around line 113-117: Add a second idempotence fixture alongside
SVELTE_FILE_ALREADY_FORMATTED that contains a <style> block already formatted
with the expected indentScriptAndStyle indentation so the test covers both
<script> and <style> idempotence; update the test constant name(s) in
crates/biome_cli/tests/cases/indent_script_and_style.rs (e.g.,
SVELTE_FILE_ALREADY_FORMATTED and the similar constant at lines ~151-152) and
ensure the test uses the new <style> fixture when invoking the
indentScriptAndStyle behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ae498607-8851-4ac5-bb1e-f68998383ea9

📥 Commits

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

⛔ Files ignored due to path filters (2)
  • crates/biome_cli/tests/snapshots/main_cases_indent_script_and_style/check_write_svelte_indent_is_idempotent.snap is excluded by !**/*.snap and included by **
  • crates/biome_cli/tests/snapshots/main_cases_indent_script_and_style/check_write_vue_indent_is_idempotent.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (11)
  • .changeset/fix-indent-script-idempotent.md
  • crates/biome_cli/tests/cases/indent_script_and_style.rs
  • crates/biome_service/src/file_handlers/css.rs
  • crates/biome_service/src/file_handlers/graphql.rs
  • crates/biome_service/src/file_handlers/html.rs
  • crates/biome_service/src/file_handlers/javascript.rs
  • crates/biome_service/src/file_handlers/json.rs
  • crates/biome_service/src/file_handlers/mod.rs
  • crates/biome_service/src/file_handlers/svelte.rs
  • crates/biome_service/src/file_handlers/vue.rs
  • crates/biome_service/src/workspace/server.rs

@ematipico ematipico merged commit 4b64145 into main Mar 17, 2026
13 checks passed
@ematipico ematipico deleted the fix/idempotency-formatting branch March 17, 2026 21:56
@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-CLI Area: CLI A-Project Area: project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 biome check --write is updating svelte files even when there are no changes

2 participants