From 48f26ca8a8a3ee962a3a696ab3e7c67d0b7a6296 Mon Sep 17 00:00:00 2001 From: PFiS1737 Date: Sat, 8 Nov 2025 18:39:59 +0800 Subject: [PATCH 1/2] fix(html/astro): keep a blank after the frontmatter --- .changeset/flat-rockets-battle.md | 5 ++ .../tests/cases/handle_astro_files.rs | 3 + .../dont_indent_frontmatter.snap | 1 + ...rmat_astro_with_typescript_script_tag.snap | 1 + .../full_support.snap | 11 +-- .../src/html/auxiliary/root.rs | 2 +- .../astro-component-casing.astro.snap | 1 + .../tests/specs/html/frontmatter.html.snap | 1 + .../html/front-matter/custom-parser.html.snap | 66 ----------------- .../html/front-matter/empty.html.snap | 53 -------------- .../html/front-matter/empty2.html.snap | 70 ------------------- .../issue-9042-no-empty-line.html.snap | 56 --------------- .../html/front-matter/issue-9042.html.snap | 57 --------------- .../prettier/html/yaml/invalid.html.snap | 65 ----------------- .../specs/prettier/html/yaml/yaml.html.snap | 7 +- 15 files changed, 22 insertions(+), 377 deletions(-) create mode 100644 .changeset/flat-rockets-battle.md delete mode 100644 crates/biome_html_formatter/tests/specs/prettier/html/front-matter/custom-parser.html.snap delete mode 100644 crates/biome_html_formatter/tests/specs/prettier/html/front-matter/empty.html.snap delete mode 100644 crates/biome_html_formatter/tests/specs/prettier/html/front-matter/empty2.html.snap delete mode 100644 crates/biome_html_formatter/tests/specs/prettier/html/front-matter/issue-9042-no-empty-line.html.snap delete mode 100644 crates/biome_html_formatter/tests/specs/prettier/html/front-matter/issue-9042.html.snap delete mode 100644 crates/biome_html_formatter/tests/specs/prettier/html/yaml/invalid.html.snap diff --git a/.changeset/flat-rockets-battle.md b/.changeset/flat-rockets-battle.md new file mode 100644 index 000000000000..c5893db20a85 --- /dev/null +++ b/.changeset/flat-rockets-battle.md @@ -0,0 +1,5 @@ +--- +"@biomejs/biome": patch +--- + +Biome now keeps a blank line after the frontmatter section in Astro files. diff --git a/crates/biome_cli/tests/cases/handle_astro_files.rs b/crates/biome_cli/tests/cases/handle_astro_files.rs index 5bccbd4ba2d3..8c2808a146d1 100644 --- a/crates/biome_cli/tests/cases/handle_astro_files.rs +++ b/crates/biome_cli/tests/cases/handle_astro_files.rs @@ -223,6 +223,9 @@ let schema = z.object().optional(); schema + sure() --- + + + Astro - 15 │ + 17 │ + 18 │ i Consider adding a generic font family as a fallback. diff --git a/crates/biome_html_formatter/src/html/auxiliary/root.rs b/crates/biome_html_formatter/src/html/auxiliary/root.rs index b12c8ebf4e14..c5d2845f96ee 100644 --- a/crates/biome_html_formatter/src/html/auxiliary/root.rs +++ b/crates/biome_html_formatter/src/html/auxiliary/root.rs @@ -18,7 +18,7 @@ impl FormatNodeRule for FormatHtmlRoot { } if let Some(frontmatter) = frontmatter { - write!(f, [frontmatter.format(), hard_line_break()])?; + write!(f, [frontmatter.format(), hard_line_break(), empty_line()])?; } if let Some(directive) = directive { diff --git a/crates/biome_html_formatter/tests/specs/html/component-frameworks/astro-component-casing.astro.snap b/crates/biome_html_formatter/tests/specs/html/component-frameworks/astro-component-casing.astro.snap index a230f4517465..7b69b59a43b4 100644 --- a/crates/biome_html_formatter/tests/specs/html/component-frameworks/astro-component-casing.astro.snap +++ b/crates/biome_html_formatter/tests/specs/html/component-frameworks/astro-component-casing.astro.snap @@ -41,6 +41,7 @@ Self close void elements: never import Button from './Button.astro'; import TextInput from './TextInput.astro'; --- + diff --git a/crates/biome_html_formatter/tests/specs/html/frontmatter.html.snap b/crates/biome_html_formatter/tests/specs/html/frontmatter.html.snap index 2e5d3a96027f..808ad5a9c7d8 100644 --- a/crates/biome_html_formatter/tests/specs/html/frontmatter.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/frontmatter.html.snap @@ -36,5 +36,6 @@ Self close void elements: never --- layout: foo --- + Test abc. ``` diff --git a/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/custom-parser.html.snap b/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/custom-parser.html.snap deleted file mode 100644 index eb1b6571d66f..000000000000 --- a/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/custom-parser.html.snap +++ /dev/null @@ -1,66 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: html/front-matter/custom-parser.html ---- -# Input - -```html ----mycustomparser - -title: Hello -slug: home - ---- - -

- Hello world!

- -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -4,5 +4,4 @@ - slug: home - - --- -- -

Hello world!

-``` - -# Output - -```html ----mycustomparser - -title: Hello -slug: home - ---- -

Hello world!

-``` - -# Errors -``` -custom-parser.html:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Frontmatter is only valid inside Astro files. - - > 1 │ ---mycustomparser - │ ^^^^^^^^^^^^^^^^^ - > 2 │ - > 3 │ title: Hello - > 4 │ slug: home - > 5 │ - > 6 │ --- - │ ^^^ - 7 │ - 8 │

- - i Remove it or rename the file to have the .astro extension. - - -``` diff --git a/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/empty.html.snap b/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/empty.html.snap deleted file mode 100644 index 21b2942d1339..000000000000 --- a/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/empty.html.snap +++ /dev/null @@ -1,53 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: html/front-matter/empty.html ---- -# Input - -```html ---- ---- - -

- Hello world!

- -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,4 +1,3 @@ - --- - --- -- -

Hello world!

-``` - -# Output - -```html ---- ---- -

Hello world!

-``` - -# Errors -``` -empty.html:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Frontmatter is only valid inside Astro files. - - > 1 │ --- - │ ^^^ - > 2 │ --- - │ ^^^ - 3 │ - 4 │

- - i Remove it or rename the file to have the .astro extension. - - -``` diff --git a/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/empty2.html.snap b/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/empty2.html.snap deleted file mode 100644 index ab29229871db..000000000000 --- a/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/empty2.html.snap +++ /dev/null @@ -1,70 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: html/front-matter/empty2.html ---- -# Input - -```html ---- ---- - -
---- -
- -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,4 +1,3 @@ - --- - --- -- -
---
-``` - -# Output - -```html ---- ---- -
---
-``` - -# Errors -``` -empty2.html:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Frontmatter is only valid inside Astro files. - - > 1 │ --- - │ ^^^ - > 2 │ --- - │ ^^^ - 3 │ - 4 │
- - i Remove it or rename the file to have the .astro extension. - -empty2.html:5:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Unexpected value or character. - - 4 │
- > 5 │ --- - │ ^^^ - 6 │
- 7 │ - - i Expected one of: - - - element - - text - - closing block - - -``` diff --git a/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/issue-9042-no-empty-line.html.snap b/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/issue-9042-no-empty-line.html.snap deleted file mode 100644 index 6caf9721766e..000000000000 --- a/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/issue-9042-no-empty-line.html.snap +++ /dev/null @@ -1,56 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: html/front-matter/issue-9042-no-empty-line.html ---- -# Input - -```html ---- -layout: foo ---- -Test abc. - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,5 +1,4 @@ - --- - layout: foo - --- -- - Test abc. -``` - -# Output - -```html ---- -layout: foo ---- -Test abc. -``` - -# Errors -``` -issue-9042-no-empty-line.html:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Frontmatter is only valid inside Astro files. - - > 1 │ --- - │ ^^^ - > 2 │ layout: foo - > 3 │ --- - │ ^^^ - 4 │ Test abc. - - i Remove it or rename the file to have the .astro extension. - - -``` diff --git a/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/issue-9042.html.snap b/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/issue-9042.html.snap deleted file mode 100644 index c360307adf1f..000000000000 --- a/crates/biome_html_formatter/tests/specs/prettier/html/front-matter/issue-9042.html.snap +++ /dev/null @@ -1,57 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: html/front-matter/issue-9042.html ---- -# Input - -```html ---- -layout: foo ---- - -Test abc. - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,5 +1,4 @@ - --- - layout: foo - --- -- - Test abc. -``` - -# Output - -```html ---- -layout: foo ---- -Test abc. -``` - -# Errors -``` -issue-9042.html:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Frontmatter is only valid inside Astro files. - - > 1 │ --- - │ ^^^ - > 2 │ layout: foo - > 3 │ --- - │ ^^^ - 4 │ - 5 │ Test - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -2,7 +2,6 @@ - invalid: - invalid: - --- -- - - - -``` - -# Output - -```html ---- - invalid: -invalid: ---- - - - - -``` - -# Errors -``` -invalid.html:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Frontmatter is only valid inside Astro files. - - > 1 │ --- - │ ^^^ - > 2 │ invalid: - > 3 │ invalid: - > 4 │ --- - │ ^^^ - 5 │ - - i Remove it or rename the file to have the .astro extension. - - -``` diff --git a/crates/biome_html_formatter/tests/specs/prettier/html/yaml/yaml.html.snap b/crates/biome_html_formatter/tests/specs/prettier/html/yaml/yaml.html.snap index b9f40d113338..0e0f60203cb3 100644 --- a/crates/biome_html_formatter/tests/specs/prettier/html/yaml/yaml.html.snap +++ b/crates/biome_html_formatter/tests/specs/prettier/html/yaml/yaml.html.snap @@ -24,15 +24,13 @@ hello: world ```diff --- Prettier +++ Biome -@@ -1,7 +1,6 @@ +@@ -1,5 +1,5 @@ --- -hello: world +hello: world --- -- + - - ``` # Output @@ -41,6 +39,7 @@ hello: world --- hello: world --- + From e660ad8fddf88a50e235be236de7f9a821064578 Mon Sep 17 00:00:00 2001 From: PFiS1737 Date: Sat, 8 Nov 2025 19:09:38 +0800 Subject: [PATCH 2/2] follow change request --- crates/biome_html_formatter/src/html/auxiliary/root.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/biome_html_formatter/src/html/auxiliary/root.rs b/crates/biome_html_formatter/src/html/auxiliary/root.rs index c5d2845f96ee..d72a0a63486d 100644 --- a/crates/biome_html_formatter/src/html/auxiliary/root.rs +++ b/crates/biome_html_formatter/src/html/auxiliary/root.rs @@ -18,7 +18,7 @@ impl FormatNodeRule for FormatHtmlRoot { } if let Some(frontmatter) = frontmatter { - write!(f, [frontmatter.format(), hard_line_break(), empty_line()])?; + write!(f, [frontmatter.format(), empty_line()])?; } if let Some(directive) = directive {