Skip to content

Conversation

@dyc3
Copy link
Contributor

@dyc3 dyc3 commented Dec 22, 2025

Summary

Fixes a minor formatting diff with prettier in the HTML formatter. Now, if a / is going to be printed and the group doesn't break, a space will preceed it.

Test Plan

snapshots

Docs

@changeset-bot
Copy link

changeset-bot bot commented Dec 22, 2025

🦋 Changeset detected

Latest commit: a9e1a65

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-Formatter Area: formatter L-HTML Language: HTML and super languages labels Dec 22, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 22, 2025

Walkthrough

This patch adds a release note for @biomejs/biome, fixes the HTML formatter to ensure a space is placed before the self-closing /> (so <Component/> becomes <Component />), and adjusts formatter logic to conditionally emit that space with line-fitting checks. A new test for a large self-closing Svelte Button component was added. No public/exported APIs were changed.

Suggested reviewers

  • ematipico

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(format/html): add space before />' accurately and concisely describes the primary change—adding space before /> in HTML self-closing elements.
Description check ✅ Passed The description clearly explains the motivation (formatting diff with Prettier), the implementation approach (conditional spacing), and references test snapshots.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dyc3/fix-html-space-in-self-closing

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f92868 and a9e1a65.

⛔ Files ignored due to path filters (7)
  • crates/biome_html_formatter/tests/specs/html/component-frameworks/astro-component-casing.astro.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_formatter/tests/specs/html/component-frameworks/svelte-component-casing.svelte.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_formatter/tests/specs/html/component-frameworks/vue-component-casing.vue.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_formatter/tests/specs/html/svelte/await_dynamic_import.svelte.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_formatter/tests/specs/html/vue/event-with-colon.vue.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_formatter/tests/specs/html/vue/issue-8174.vue.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (3)
  • .changeset/rotten-pans-ring.md
  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
  • crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: dyc3
Repo: biomejs/biome PR: 8291
File: crates/biome_html_formatter/tests/specs/prettier/vue/html-vue/elastic-header.html:10-10
Timestamp: 2025-12-04T13:29:49.287Z
Learning: Files under `crates/biome_html_formatter/tests/specs/prettier` are test fixtures synced from Prettier and should not receive detailed code quality reviews (e.g., HTTP vs HTTPS, formatting suggestions, etc.). These files are test data meant to validate formatter behavior and should be preserved as-is.
📚 Learning: 2025-12-04T13:29:49.287Z
Learnt from: dyc3
Repo: biomejs/biome PR: 8291
File: crates/biome_html_formatter/tests/specs/prettier/vue/html-vue/elastic-header.html:10-10
Timestamp: 2025-12-04T13:29:49.287Z
Learning: Files under `crates/biome_html_formatter/tests/specs/prettier` are test fixtures synced from Prettier and should not receive detailed code quality reviews (e.g., HTTP vs HTTPS, formatting suggestions, etc.). These files are test data meant to validate formatter behavior and should be preserved as-is.

Applied to files:

  • .changeset/rotten-pans-ring.md
  • crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte
📚 Learning: 2025-12-21T21:15:03.782Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.782Z
Learning: Changesets should describe user-facing changes only; internal refactoring without behavior changes does not require a changeset

Applied to files:

  • .changeset/rotten-pans-ring.md
📚 Learning: 2025-12-21T21:15:03.782Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.782Z
Learning: For formatter changes in changesets, show formatting changes using diff code blocks

Applied to files:

  • .changeset/rotten-pans-ring.md
🪛 LanguageTool
.changeset/rotten-pans-ring.md

[style] ~4-~4: Consider using a different verb for a more formal wording.
Context: --- "@biomejs/biome": patch --- Fixed an issue with the HTML formatter where ...

(FIX_RESOLVE)


[misspelling] ~5-~5: This word is normally spelled with a hyphen.
Context: ...wouldn't add a space before the /> in self closing elements. This brings the HTML formatte...

(EN_COMPOUNDS_SELF_CLOSING)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: End-to-end tests
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test Node.js API
  • GitHub Check: autofix
🔇 Additional comments (1)
crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte (1)

1-6: LGTM! Appropriate test fixture for the formatter fix.

This test case effectively demonstrates the formatter's behavior with a multi-line self-closing tag.


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

🧹 Nitpick comments (2)
.changeset/rotten-pans-ring.md (1)

1-5: Consider adding a formatting example.

Per coding guidelines, showing the before/after formatting behaviour with a diff block would clarify the fix for users.

Based on learnings, formatter changes in changesets benefit from formatting examples.

💡 Example addition
 ---
 "@biomejs/biome": patch
 ---
 
 Fixed an issue with the HTML formatter where it wouldn't add a space before the `/>` in self-closing elements. This brings the HTML formatter more in line with Prettier.
+
+Before:
+```html
+<Button label="test"/>
+```
+
+After:
+```html
+<Button label="test" />
+```
crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs (1)

70-73: Consider simplifying the pattern match.

Since you're not using the inner value (indicated by _), slash_token.is_some() might be clearer than if let Some(_).

💡 Alternative approach
-                } else {
-                    if let Some(_) = &slash_token {
-                        // only add a space before the slash if it exists.
-                        write!(f, [space()])?;
-                    }
-                    write!(f, [slash_token.format()])?;
-                }
+                } else {
+                    if slash_token.is_some() {
+                        // only add a space before the slash if it exists.
+                        write!(f, [space()])?;
+                    }
+                    write!(f, [slash_token.format()])?;
+                }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 619ac39 and 372dd60.

⛔ Files ignored due to path filters (7)
  • crates/biome_html_formatter/tests/specs/html/component-frameworks/astro-component-casing.astro.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_formatter/tests/specs/html/component-frameworks/svelte-component-casing.svelte.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_formatter/tests/specs/html/component-frameworks/vue-component-casing.vue.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_formatter/tests/specs/html/svelte/await_dynamic_import.svelte.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_formatter/tests/specs/html/vue/event-with-colon.vue.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_formatter/tests/specs/html/vue/issue-8174.vue.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (3)
  • .changeset/rotten-pans-ring.md
  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
  • crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use inline rustdoc documentation for rules, assists, and their options
Use the dbg!() macro for debugging output in Rust tests and code
Use doc tests (doctest) format with code blocks in rustdoc comments; ensure assertions pass in tests

Files:

  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
🧠 Learnings (13)
📓 Common learnings
Learnt from: dyc3
Repo: biomejs/biome PR: 8291
File: crates/biome_html_formatter/tests/specs/prettier/vue/html-vue/elastic-header.html:10-10
Timestamp: 2025-12-04T13:29:49.287Z
Learning: Files under `crates/biome_html_formatter/tests/specs/prettier` are test fixtures synced from Prettier and should not receive detailed code quality reviews (e.g., HTTP vs HTTPS, formatting suggestions, etc.). These files are test data meant to validate formatter behavior and should be preserved as-is.
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.782Z
Learning: For formatter changes in changesets, show formatting changes using diff code blocks
📚 Learning: 2025-12-04T13:29:49.287Z
Learnt from: dyc3
Repo: biomejs/biome PR: 8291
File: crates/biome_html_formatter/tests/specs/prettier/vue/html-vue/elastic-header.html:10-10
Timestamp: 2025-12-04T13:29:49.287Z
Learning: Files under `crates/biome_html_formatter/tests/specs/prettier` are test fixtures synced from Prettier and should not receive detailed code quality reviews (e.g., HTTP vs HTTPS, formatting suggestions, etc.). These files are test data meant to validate formatter behavior and should be preserved as-is.

Applied to files:

  • crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte
  • .changeset/rotten-pans-ring.md
📚 Learning: 2025-12-21T21:15:03.782Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.782Z
Learning: For formatter changes in changesets, show formatting changes using diff code blocks

Applied to files:

  • .changeset/rotten-pans-ring.md
📚 Learning: 2025-11-24T18:05:27.810Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.810Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : When formatting AST nodes, use mandatory tokens from the AST instead of hardcoding token strings (e.g., use `node.l_paren_token().format()` instead of `token("(")`)

Applied to files:

  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/**/*.rs : Prefix line with `#` in documentation code examples sparingly; prefer concise complete snippets

Applied to files:

  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
📚 Learning: 2025-11-24T18:05:27.810Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.810Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Do not attempt to 'fix' the code; if a token/node is known to be mandatory but is missing, return `None` instead

Applied to files:

  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
📚 Learning: 2025-11-24T18:05:27.810Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.810Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : For tokens that are not mandatory, use helper functions instead of hardcoding

Applied to files:

  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Use `p.eat(token)` for optional tokens, `p.expect(token)` for required tokens, `parse_rule(p).ok(p)` for optional nodes, and `parse_rule(p).or_add_diagnostic(p, error)` for required nodes

Applied to files:

  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/**/*.rs : Lines prefixed with `#` in rule documentation code examples will be hidden from output

Applied to files:

  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/**/*.rs : Avoid string allocations by comparing against `&str` or using `TokenText`

Applied to files:

  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/**/*.rs : The first paragraph of rule documentation must be a single line describing what the rule does

Applied to files:

  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Use `ConditionalParsedSyntax` for syntax that is only valid in specific contexts (e.g., strict mode, file types, language versions) and call `or_invalid_to_bogus()` to convert to a bogus node if not supported

Applied to files:

  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Implement a token source struct that wraps the lexer and implements `TokenSourceWithBufferedLexer` and `LexerWithCheckpoint` for lookahead and re-lexing capabilities

Applied to files:

  • crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
🧬 Code graph analysis (1)
crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs (1)
crates/biome_formatter/src/builders.rs (3)
  • if_group_fits_on_line (2024-2033)
  • space (606-608)
  • token (251-259)
🪛 LanguageTool
.changeset/rotten-pans-ring.md

[style] ~4-~4: Consider using a different verb for a more formal wording.
Context: --- "@biomejs/biome": patch --- Fixed an issue with the HTML formatter where ...

(FIX_RESOLVE)


[misspelling] ~5-~5: This word is normally spelled with a hyphen.
Context: ...wouldn't add a space before the /> in self closing elements. This brings the HTML formatte...

(EN_COMPOUNDS_SELF_CLOSING)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Documentation
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: End-to-end tests
  • GitHub Check: Check Dependencies
  • GitHub Check: Test Node.js API
  • GitHub Check: autofix
🔇 Additional comments (2)
crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs (1)

59-59: Conditional spacing logic looks correct.

The use of if_group_fits_on_line(&space()) appropriately adds space before the slash only when the group fits on a single line, maintaining alignment with Prettier's behaviour.

Also applies to: 61-61

crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte (1)

1-6: Test fixture looks appropriate.

The test case appropriately covers a large self-closing component to validate the spacing fix.

"@biomejs/biome": patch
---

Fixed an issue with the HTML formatter where it wouldn't add a space before the `/>` in self closing elements. This brings the HTML formatter more in line with Prettier.
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

Hyphenate "self-closing".

The term should be "self-closing" with a hyphen.

🔎 Proposed fix
-Fixed an issue with the HTML formatter where it wouldn't add a space before the `/>` in self closing elements. This brings the HTML formatter more in line with Prettier.
+Fixed an issue with the HTML formatter where it wouldn't add a space before the `/>` in self-closing elements. This brings the HTML formatter more in line with Prettier.
📝 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 an issue with the HTML formatter where it wouldn't add a space before the `/>` in self closing elements. This brings the HTML formatter more in line with Prettier.
Fixed an issue with the HTML formatter where it wouldn't add a space before the `/>` in self-closing elements. This brings the HTML formatter more in line with Prettier.
🧰 Tools
🪛 LanguageTool

[misspelling] ~5-~5: This word is normally spelled with a hyphen.
Context: ...wouldn't add a space before the /> in self closing elements. This brings the HTML formatte...

(EN_COMPOUNDS_SELF_CLOSING)

🤖 Prompt for AI Agents
In .changeset/rotten-pans-ring.md around line 5, the phrase "self closing
elements" should be hyphenated; change it to "self-closing elements" so the
changelog uses the correct term and punctuation.

@dyc3 dyc3 force-pushed the dyc3/fix-html-space-in-self-closing branch from 372dd60 to 7f92868 Compare December 22, 2025 19:44
@dyc3 dyc3 force-pushed the dyc3/fix-html-space-in-self-closing branch from 7f92868 to a9e1a65 Compare December 23, 2025 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants