Skip to content

fix(formatter): switch case comments#9303

Merged
ematipico merged 1 commit intomainfrom
fix/idempotence-switch-ase
Mar 2, 2026
Merged

fix(formatter): switch case comments#9303
ematipico merged 1 commit intomainfrom
fix/idempotence-switch-ase

Conversation

@ematipico
Copy link
Member

Summary

Closes #2786

Found the fix with AI

Test Plan

Added a test

Docs

@changeset-bot
Copy link

changeset-bot bot commented Mar 2, 2026

🦋 Changeset detected

Latest commit: c43e45d

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

@ematipico ematipico requested review from a team March 2, 2026 21:21
@github-actions github-actions bot added A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages labels Mar 2, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

Walkthrough

This pull request addresses an idempotence issue in the JavaScript formatter where trailing line comments after case clauses were causing unstable output across multiple formatting passes. The fix introduces a conditional guard in the case clause formatter to prevent block statement hugging when a trailing comment follows the case colon. Changes include updates to the case clause formatter logic, new test coverage for switch statements with inline trailing comments, and documentation via a changeset file.

Suggested labels

A-Formatter, L-JavaScript

Suggested reviewers

  • dyc3
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(formatter): switch case comments' directly addresses the main change—fixing formatter idempotence for switch case comments.
Description check ✅ Passed The description references the linked issue #2786, discloses AI assistance, and mentions a test was added, all relevant to the changeset.
Linked Issues check ✅ Passed The PR implementation aligns with issue #2786 objectives: adds a guard to prevent comment dissociation, ensures idempotent formatting of switch case comments, and includes a test case.
Out of Scope Changes check ✅ Passed All changes (formatter logic, test cases, and changeset documentation) are directly scoped to fixing switch case comment idempotence per issue #2786.

✏️ 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
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/idempotence-switch-ase

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

Copy link
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: 1

🤖 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/fix-switch-case-comment-idempotence.md:
- Line 5: Update the changeset body in
.changeset/fix-switch-case-comment-idempotence.md to include a before/after
formatter diff code block showing the concrete visible change (use a unified
diff-style snippet); insert a fenced code block (```diff) containing the
original lines (prefixed with -) and the formatted lines (prefixed with +) —
e.g., show the "-case 1337: {", "-  // ELITE", "-  console.log(\"x is cool\");",
"-}" and the corresponding "+case 1337: // ELITE", "+{", "+  console.log(\"x is
cool\");", "+}" lines — so users can see the exact formatting change.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1003229 and f583ef5.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_formatter/tests/specs/js/module/statement/switch_comment.js.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (4)
  • .changeset/fix-switch-case-comment-idempotence.md
  • crates/biome_js_formatter/src/js/auxiliary/case_clause.rs
  • crates/biome_js_formatter/tests/quick_test.rs
  • crates/biome_js_formatter/tests/specs/js/module/statement/switch_comment.js

"@biomejs/biome": patch
---

Fixed [#2786](https://github.com/biomejs/biome/issues/2786): The formatter no longer produces different output on subsequent runs when a `case` clause has a trailing line comment followed by a single block statement.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add a tiny before/after formatter diff in the changeset body.

Nice summary, but this formatter fix should include a concrete formatting diff so users can see the visible behaviour change at a glance.

Suggested changeset snippet
 Fixed [`#2786`](https://github.com/biomejs/biome/issues/2786): The formatter no longer produces different output on subsequent runs when a `case` clause has a trailing line comment followed by a single block statement.

+```diff
+-case 1337: {
+-  // ELITE
++case 1337: // ELITE
++{
+   console.log("x is cool");
+ }
+```

As per coding guidelines: for formatter changes in changesets, show formatting changes using diff code blocks.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Fixed [#2786](https://github.com/biomejs/biome/issues/2786): The formatter no longer produces different output on subsequent runs when a `case` clause has a trailing line comment followed by a single block statement.
---
package: `@biomejs/biome`
type: patch
---
Fixed [`#2786`](https://github.com/biomejs/biome/issues/2786): The formatter no longer produces different output on subsequent runs when a `case` clause has a trailing line comment followed by a single block statement.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.changeset/fix-switch-case-comment-idempotence.md at line 5, Update the
changeset body in .changeset/fix-switch-case-comment-idempotence.md to include a
before/after formatter diff code block showing the concrete visible change (use
a unified diff-style snippet); insert a fenced code block (```diff) containing
the original lines (prefixed with -) and the formatted lines (prefixed with +) —
e.g., show the "-case 1337: {", "-  // ELITE", "-  console.log(\"x is cool\");",
"-}" and the corresponding "+case 1337: // ELITE", "+{", "+  console.log(\"x is
cool\");", "+}" lines — so users can see the exact formatting change.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 2, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 156 skipped benchmarks1


Comparing fix/idempotence-switch-ase (c43e45d) with main (3bc07ab)

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.

Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

revert quick test

@ematipico ematipico force-pushed the fix/idempotence-switch-ase branch from f583ef5 to c43e45d Compare March 2, 2026 22:00
@ematipico ematipico merged commit 464910c into main Mar 2, 2026
15 of 16 checks passed
@ematipico ematipico deleted the fix/idempotence-switch-ase branch March 2, 2026 22:01
@github-actions github-actions bot mentioned this pull request Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📝 Line comment for case: statement is dissociated by unstable formatting

2 participants