-
-
Notifications
You must be signed in to change notification settings - Fork 1k
fix(format/html): preserve block indentation if already present in some cases #9757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --- | ||
| "@biomejs/biome": patch | ||
| --- | ||
|
|
||
| Fixed [#9099](https://github.com/biomejs/biome/issues/9099): the HTML formatter collapsing non-text children (inline elements, Svelte expressions, comments) onto a single line when the source had them on separate lines. Biome now preserves the user's intended line breaks for exclusively non-text children. | ||
|
|
||
| For example, the following Svelte snippet is now preserved instead of being collapsed to `<div>{name}<!-- comment --></div>`: | ||
|
|
||
| ```svelte | ||
| <div> | ||
| {name}<!-- comment --> | ||
| </div> | ||
| ``` | ||
|
|
||
| Similarly, HTML elements like `<span>` inside a `<div>` are now preserved when written on their own line: | ||
|
|
||
| ```html | ||
| <div> | ||
| <span>text</span> | ||
| </div> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --- | ||
| "@biomejs/biome": patch | ||
| --- | ||
|
|
||
| Fixed [#9450](https://github.com/biomejs/biome/issues/9450): the HTML formatter now correctly preserves multiline formatting for nested `<template>` elements (e.g. `<template #body>`) when the source has children on separate lines. Previously, the children were collapsed onto a single line. | ||
|
|
||
| ```diff | ||
| <template> | ||
| <UModal> | ||
| - <template #body> <p>content</p> </template> | ||
| + <template #body> | ||
| + <p>content</p> | ||
| + </template> | ||
| </UModal> | ||
| </template> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
crates/biome_html_formatter/tests/specs/html/svelte/preserve_newline_nontext_children.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <!-- Newlines around expression should be preserved --> | ||
| <div> | ||
| {name} | ||
| </div> | ||
|
|
||
| <!-- No newlines = stays inline --> | ||
| <div>{name}</div> | ||
|
|
||
| <!-- Newlines around expression + comment should be preserved --> | ||
| <div> | ||
| {name}<!-- comment --> | ||
| </div> | ||
|
|
||
| <!-- No newlines around expression + comment = stays inline --> | ||
| <div>{name}<!-- comment --></div> | ||
|
|
||
| <!-- Multiple expressions with newlines --> | ||
| <div> | ||
| {foo} | ||
| {bar} | ||
| </div> |
59 changes: 59 additions & 0 deletions
59
...iome_html_formatter/tests/specs/html/svelte/preserve_newline_nontext_children.svelte.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| --- | ||
| source: crates/biome_formatter_test/src/snapshot_builder.rs | ||
| info: svelte/preserve_newline_nontext_children.svelte | ||
| --- | ||
|
|
||
| # Input | ||
|
|
||
| ```svelte | ||
| <!-- Newlines around expression should be preserved --> | ||
| <div> | ||
| {name} | ||
| </div> | ||
|
|
||
| <!-- No newlines = stays inline --> | ||
| <div>{name}</div> | ||
|
|
||
| <!-- Newlines around expression + comment should be preserved --> | ||
| <div> | ||
| {name}<!-- comment --> | ||
| </div> | ||
|
|
||
| <!-- No newlines around expression + comment = stays inline --> | ||
| <div>{name}<!-- comment --></div> | ||
|
|
||
| <!-- Multiple expressions with newlines --> | ||
| <div> | ||
| {foo} | ||
| {bar} | ||
| </div> | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| # Formatted | ||
|
|
||
| ```svelte | ||
| <!-- Newlines around expression should be preserved --> | ||
| <div> | ||
| {name} | ||
| </div> | ||
|
|
||
| <!-- No newlines = stays inline --> | ||
| <div>{name}</div> | ||
|
|
||
| <!-- Newlines around expression + comment should be preserved --> | ||
| <div> | ||
| {name}<!-- comment --> | ||
| </div> | ||
|
|
||
| <!-- No newlines around expression + comment = stays inline --> | ||
| <div>{name}<!-- comment --></div> | ||
|
|
||
| <!-- Multiple expressions with newlines --> | ||
| <div> | ||
| {foo} | ||
| {bar} | ||
| </div> | ||
|
|
||
| ``` |
21 changes: 21 additions & 0 deletions
21
crates/biome_html_formatter/tests/specs/html/vue/inner-template.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <template> | ||
| <UModal> | ||
| <!-- | ||
| because the children of this inner template already has a newline, | ||
| the multiline formatting should be preserved | ||
| --> | ||
| <template #body> | ||
| <p>{{ store.options.text }}</p> | ||
| </template> | ||
| </UModal> | ||
| </template> | ||
|
|
||
| <template> | ||
| <UModal> | ||
| <!-- | ||
| because the children of this inner template does not have a newline, | ||
| the children should NOT be multiline formatted | ||
| --> | ||
| <template #body><p>foo</p></template> | ||
| </UModal> | ||
| </template> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.