-
-
Notifications
You must be signed in to change notification settings - Fork 760
fix(html/astro): don't indent Astro frontmatter #8037
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
Conversation
🦋 Changeset detectedLatest commit: 0fe1ef0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
WalkthroughSwitches the Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (6)📚 Learning: 2025-10-15T09:22:46.002ZApplied to files:
📚 Learning: 2025-10-15T09:24:31.042ZApplied to files:
📚 Learning: 2025-10-15T09:22:46.002ZApplied to files:
📚 Learning: 2025-10-15T09:23:33.055ZApplied to files:
📚 Learning: 2025-10-15T09:23:33.055ZApplied to files:
📚 Learning: 2025-10-15T09:22:15.851ZApplied to files:
🧬 Code graph analysis (1)crates/biome_js_syntax/src/file_source.rs (2)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/biome_js_syntax/src/file_source.rs (1)
124-126: Consider adding a helper method for consistency.The new
AstroFrontmattervariant looks good, but other variants (Astro,Vue,Svelte) have correspondingis_*()helper methods (lines 134-142). For API consistency, consider adding:impl EmbeddingKind { pub const fn is_astro(&self) -> bool { matches!(self, Self::Astro) } + pub const fn is_astro_frontmatter(&self) -> bool { + matches!(self, Self::AstroFrontmatter) + } pub const fn is_vue(&self) -> bool { matches!(self, Self::Vue) }This would allow direct checks like
embedding_kind.is_astro_frontmatter()rather than pattern matching, though it's optional if the variant is only used inmatchexpressions.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/dont_indent_frontmatter.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (5)
.changeset/vast-donuts-rescue.md(1 hunks)crates/biome_cli/tests/cases/handle_astro_files.rs(1 hunks)crates/biome_js_syntax/src/file_source.rs(1 hunks)crates/biome_service/src/file_handlers/html.rs(3 hunks)crates/biome_service/src/file_handlers/mod.rs(1 hunks)
🧰 Additional context used
🧠 Learnings (22)
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Import and use the `FormatNode` trait for AST nodes
Applied to files:
crates/biome_js_syntax/src/file_source.rscrates/biome_service/src/file_handlers/mod.rscrates/biome_service/src/file_handlers/html.rscrates/biome_cli/tests/cases/handle_astro_files.rs
📚 Learning: 2025-10-15T09:24:31.042Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:24:31.042Z
Learning: Applies to crates/biome_parser/xtask/codegen/src/*_kinds_src.rs : Add src/<lang>_kinds_src.rs under xtask/codegen that returns a static KindSrc
Applied to files:
crates/biome_js_syntax/src/file_source.rscrates/biome_service/src/file_handlers/mod.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : When a token is mandatory and present in the AST, use the AST-provided token (e.g., `node.l_paren_token().format()`) instead of emitting a static token
Applied to files:
crates/biome_js_syntax/src/file_source.rscrates/biome_service/src/file_handlers/mod.rscrates/biome_service/src/file_handlers/html.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/src/type_info.rs : Add new TypeScript type support by extending the TypeData enum rather than introducing parallel structures.
Applied to files:
crates/biome_js_syntax/src/file_source.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/src/**/*.rs : After generation, remove usages of `format_verbatim_node` and implement real formatting with biome_formatter utilities
Applied to files:
crates/biome_service/src/file_handlers/mod.rscrates/biome_service/src/file_handlers/html.rscrates/biome_cli/tests/cases/handle_astro_files.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/src/{type_info,local_inference,resolver,flattening}.rs : Avoid recursive type structures and cross-module Arcs; represent links between types using TypeReference and TypeData::Reference.
Applied to files:
crates/biome_service/src/file_handlers/mod.rscrates/biome_service/src/file_handlers/html.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Implement the `Format` trait for your node type and use `JsFormatter` with `write!`/`format_args!` to define formatting
Applied to files:
crates/biome_service/src/file_handlers/html.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Do not attempt to fix code; if a mandatory token/node is missing, return `None` instead
Applied to files:
crates/biome_service/src/file_handlers/html.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/src/cst.rs : Create FormatHtmlSyntaxNode in cst.rs implementing FormatRule<HtmlSyntaxNode> and AsFormat/IntoFormat for HtmlSyntaxNode using the provided plumbing
Applied to files:
crates/biome_service/src/file_handlers/html.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : For non-mandatory tokens, use the provided helper constructors (e.g., `token`, `space_token`, `dynamic_token`)
Applied to files:
crates/biome_service/src/file_handlers/html.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/src/context.rs : Create HtmlFormatContext in context.rs with comments and source_map fields and implement FormatContext and CstFormatContext
Applied to files:
crates/biome_service/src/file_handlers/html.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/Cargo.toml : Declare the dependency `biome_js_formatter = { version = "0.0.1", path = "../biome_js_formatter" }` for internal installation
Applied to files:
crates/biome_service/src/file_handlers/html.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/src/lib.rs : Expose a documented public function `format_node(options: HtmlFormatOptions, root: &HtmlSyntaxNode) -> FormatResult<Formatted<HtmlFormatContext>>` delegating to `biome_formatter::format_node`
Applied to files:
crates/biome_service/src/file_handlers/html.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/src/lib.rs : Implement FormatLanguage for HtmlFormatLanguage with associated types: SyntaxLanguage=HtmlLanguage, Context=HtmlFormatContext, FormatRule=FormatHtmlSyntaxNode
Applied to files:
crates/biome_service/src/file_handlers/html.rs
📚 Learning: 2025-10-15T09:25:05.698Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:25:05.698Z
Learning: Applies to crates/biome_service/../biome_lsp/src/server.tests.rs : Keep end-to-end LSP tests in ../biome_lsp/src/server.tests.rs
Applied to files:
crates/biome_cli/tests/cases/handle_astro_files.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/tests/spec_tests.rs : In tests/spec_tests.rs, generate tests with `tests_macros::gen_tests! {"tests/specs/html/**/*.html", crate::spec_test::run, ""}`
Applied to files:
crates/biome_cli/tests/cases/handle_astro_files.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/tests/spec_test.rs : Implement a `run` function in tests/spec_test.rs that wires SpecSnapshot and includes!("language.rs") as shown
Applied to files:
crates/biome_cli/tests/cases/handle_astro_files.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/tests/** : Create a tests directory containing a specs subfolder and the files spec_test.rs, spec_tests.rs, and language.rs
Applied to files:
crates/biome_cli/tests/cases/handle_astro_files.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/tests/language.rs : Create tests/language.rs defining `HtmlTestFormatLanguage` and implement the TestFormatLanguage trait
Applied to files:
crates/biome_cli/tests/cases/handle_astro_files.rs
📚 Learning: 2025-10-15T09:25:05.698Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:25:05.698Z
Learning: Applies to crates/biome_service/src/workspace/watcher.tests.rs : Place watcher tests related to workspace methods in src/workspace/watcher.tests.rs
Applied to files:
crates/biome_cli/tests/cases/handle_astro_files.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/**/Cargo.toml : Add the specified dev-dependencies under [dev-dependencies] for the test infrastructure
Applied to files:
crates/biome_cli/tests/cases/handle_astro_files.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/tests/specs/html/**/*.html : Place HTML test cases under tests/specs/html as .html files discovered by the test macro
Applied to files:
crates/biome_cli/tests/cases/handle_astro_files.rs
🧬 Code graph analysis (3)
crates/biome_service/src/file_handlers/mod.rs (1)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (1)
EmbeddingKind(9597-9597)
crates/biome_service/src/file_handlers/html.rs (4)
crates/biome_service/src/file_handlers/vue.rs (1)
file_source(67-80)crates/biome_service/src/file_handlers/svelte.rs (1)
file_source(67-80)packages/@biomejs/backend-jsonrpc/src/workspace.ts (3)
JsFileSource(9570-9579)EmbeddingKind(9597-9597)DocumentFileSource(9561-9569)crates/biome_js_syntax/src/file_source.rs (1)
ts(176-183)
crates/biome_cli/tests/cases/handle_astro_files.rs (3)
crates/biome_service/src/file_handlers/mod.rs (12)
new(565-579)new(796-810)new(1055-1073)new(1387-1401)new(1556-1566)from(88-90)from(94-96)from(100-102)from(106-108)from(112-114)from(118-120)from(124-126)crates/biome_cli/tests/main.rs (1)
run_cli(332-347)crates/biome_cli/tests/snap_test.rs (1)
assert_cli_snapshot(407-409)
🔇 Additional comments (6)
.changeset/vast-donuts-rescue.md (1)
1-5: LGTM – Clear changeset documentation.The changeset accurately describes the user-facing behaviour change.
crates/biome_cli/tests/cases/handle_astro_files.rs (1)
671-717: Well-structured test for the new behaviour.The test properly validates that Astro frontmatter remains unindented whilst regular
<script>and<style>tags are indented whenindentScriptAndStyleis enabled. Good coverage of the differential behaviour.crates/biome_service/src/file_handlers/mod.rs (1)
817-817: Correct capability alignment for AstroFrontmatter.Treating
AstroFrontmatterthe same asAstrofor capabilities lookup ensures consistent file handling behaviour.crates/biome_service/src/file_handlers/html.rs (3)
448-448: Correct use of AstroFrontmatter embedding kind.The Astro frontmatter content is now properly tagged with
EmbeddingKind::AstroFrontmatter, enabling differentiated formatting behaviour.
675-693: Clean implementation of conditional indentation.The logic correctly skips indentation when either
indent_script_and_styleis false or the content is Astro frontmatter. The nested structure (hard line → indent → hard line → content → end indent) vs. (hard line → content) is appropriate for the two cases.
696-720: Proper frontmatter flag propagation.The formatting correctly passes the frontmatter check for JavaScript embeddings (line 704) whilst JSON (line 713) and CSS (line 720) are marked as non-frontmatter. This ensures only Astro frontmatter sections bypass indentation.
This reverts commit f3b9b30.
There was a problem hiding this 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 (1)
crates/biome_js_syntax/src/file_source.rs (1)
133-138: Consider the semantic clarity ofis_astro().The method
is_astro()now returnstrueonly forfrontmatter: false, which might be unexpected. Callers might reasonably assume this method returnstruefor all Astro code, including frontmatter. Consider whetheris_astro_script()oris_astro_non_frontmatter()would more clearly communicate the intent, or alternatively, haveis_astro()match both variants usingmatches!(self, Self::Astro { .. }).
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
packages/@biomejs/backend-jsonrpc/src/workspace.tsis excluded by!**/backend-jsonrpc/src/workspace.tsand included by**
📒 Files selected for processing (4)
crates/biome_js_syntax/src/file_source.rs(3 hunks)crates/biome_service/src/file_handlers/html.rs(4 hunks)crates/biome_service/src/file_handlers/mod.rs(1 hunks)xtask/rules_check/src/lib.rs(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- crates/biome_service/src/file_handlers/html.rs
🧰 Additional context used
🧠 Learnings (7)
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Import and use the `FormatNode` trait for AST nodes
Applied to files:
crates/biome_service/src/file_handlers/mod.rscrates/biome_js_syntax/src/file_source.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/src/{type_info,local_inference,resolver,flattening}.rs : Avoid recursive type structures and cross-module Arcs; represent links between types using TypeReference and TypeData::Reference.
Applied to files:
crates/biome_service/src/file_handlers/mod.rscrates/biome_js_syntax/src/file_source.rsxtask/rules_check/src/lib.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/src/**/*.rs : After generation, remove usages of `format_verbatim_node` and implement real formatting with biome_formatter utilities
Applied to files:
crates/biome_service/src/file_handlers/mod.rs
📚 Learning: 2025-10-15T09:24:31.042Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:24:31.042Z
Learning: Applies to crates/biome_parser/xtask/codegen/src/*_kinds_src.rs : Add src/<lang>_kinds_src.rs under xtask/codegen that returns a static KindSrc
Applied to files:
crates/biome_service/src/file_handlers/mod.rscrates/biome_js_syntax/src/file_source.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : When a token is mandatory and present in the AST, use the AST-provided token (e.g., `node.l_paren_token().format()`) instead of emitting a static token
Applied to files:
crates/biome_service/src/file_handlers/mod.rscrates/biome_js_syntax/src/file_source.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Do not attempt to fix code; if a mandatory token/node is missing, return `None` instead
Applied to files:
crates/biome_service/src/file_handlers/mod.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/src/type_info.rs : Add new TypeScript type support by extending the TypeData enum rather than introducing parallel structures.
Applied to files:
crates/biome_js_syntax/src/file_source.rs
🧬 Code graph analysis (3)
crates/biome_service/src/file_handlers/mod.rs (1)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (1)
EmbeddingKind(9597-9602)
crates/biome_js_syntax/src/file_source.rs (2)
crates/biome_html_syntax/src/generated/nodes.rs (1)
frontmatter(618-620)packages/@biomejs/backend-jsonrpc/src/workspace.ts (1)
EmbeddingKind(9597-9602)
xtask/rules_check/src/lib.rs (1)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (1)
EmbeddingKind(9597-9602)
🔇 Additional comments (3)
xtask/rules_check/src/lib.rs (1)
288-288: Pattern match correctly updated for struct variant.The wildcard pattern
{ .. }appropriately matches all Astro embedding variants, ensuring both frontmatter and non-frontmatter code is processed consistently.crates/biome_service/src/file_handlers/mod.rs (1)
817-817: Capabilities routing correctly updated.All Astro embedding variants are now properly routed to the Astro file handler, regardless of the frontmatter state.
crates/biome_js_syntax/src/file_source.rs (1)
208-213: Constructor implementation is sound.The
astro()andastro_frontmatter()constructors provide clear, distinct entry points for creating both Astro embedding variants.
ematipico
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great fix @PFiS1737 , users will appreciate it!
CodSpeed Performance ReportMerging #8037 will not alter performanceComparing Summary
Footnotes
|
Summary
As I mentioned in discussion #8033,
indentScriptAndStyleshouldn’t indent the frontmatter section in Astro files. I tried modifying the code accordingly, and it seems to work as expected.However, I’ve only been working with Biome development for about three hours, so I’m not sure whether this change might have any side effects.
Test Plan
Added snap test.
Docs