-
-
Notifications
You must be signed in to change notification settings - Fork 808
refactor(formatter): introduce the SourcePosition element and remove source position from Text and LocatedTokenText variant #8012
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 83cb4cc 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 |
Parser conformance results onjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
…source position from Text and LocatedTokenText variant
f21050d to
b888584
Compare
CodSpeed Performance ReportMerging #8012 will degrade performances by 7.99%Comparing Summary
Benchmarks breakdown
Footnotes
|
WalkthroughThis PR centralises source-position tracking in the formatter: it removes Possibly related PRs
Suggested labels
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)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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). (21)
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_formatter/src/builders.rs (1)
434-440: Consider using the helper for consistency.Line 436 writes
FormatElement::SourcePositiondirectly, bypassing the IR-level deduplication in thesource_position()helper (lines 321–325). For consistency withText::fmt(line 349) andSyntaxTokenCowSlice::fmt(line 384), consider:- f.write_element(FormatElement::SourcePosition(self.source_position))?; + source_position(self.source_position).fmt(f)?;This avoids potential consecutive duplicate SourcePosition elements in the IR.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (34)
.changeset/real-tires-move.md(1 hunks)crates/biome_css_formatter/src/comments.rs(2 hunks)crates/biome_css_formatter/src/css/value/url_value_raw.rs(1 hunks)crates/biome_css_formatter/src/lib.rs(1 hunks)crates/biome_css_formatter/src/utils/string_utils.rs(1 hunks)crates/biome_css_formatter/src/verbatim.rs(1 hunks)crates/biome_css_semantic/src/format_semantic_model.rs(5 hunks)crates/biome_formatter/src/builders.rs(7 hunks)crates/biome_formatter/src/format_element.rs(5 hunks)crates/biome_formatter/src/format_element/document.rs(14 hunks)crates/biome_formatter/src/format_extensions.rs(2 hunks)crates/biome_formatter/src/lib.rs(1 hunks)crates/biome_formatter/src/macros.rs(1 hunks)crates/biome_formatter/src/printer/mod.rs(12 hunks)crates/biome_graphql_formatter/src/comments.rs(2 hunks)crates/biome_graphql_formatter/src/graphql/value/string_value.rs(1 hunks)crates/biome_graphql_formatter/src/verbatim.rs(1 hunks)crates/biome_grit_formatter/src/comments.rs(2 hunks)crates/biome_grit_formatter/src/verbatim.rs(1 hunks)crates/biome_html_formatter/src/utils/children.rs(1 hunks)crates/biome_html_formatter/src/utils/formatters.rs(1 hunks)crates/biome_html_formatter/src/verbatim.rs(1 hunks)crates/biome_js_formatter/src/comments.rs(2 hunks)crates/biome_js_formatter/src/js/expressions/bigint_literal_expression.rs(1 hunks)crates/biome_js_formatter/src/ts/types/bigint_literal_type.rs(1 hunks)crates/biome_js_formatter/src/utils/jsx.rs(1 hunks)crates/biome_js_formatter/src/utils/test_each_template.rs(1 hunks)crates/biome_js_formatter/src/verbatim.rs(1 hunks)crates/biome_js_semantic/src/format_semantic_model.rs(4 hunks)crates/biome_js_type_info/src/format_type_info.rs(18 hunks)crates/biome_jsdoc_comment/src/format_jsdoc_comment.rs(1 hunks)crates/biome_json_formatter/src/comments.rs(2 hunks)crates/biome_json_formatter/src/verbatim.rs(1 hunks)crates/biome_module_graph/src/format_module_graph.rs(6 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
crates/biome_js_formatter/**/*.rs
📄 CodeRabbit inference engine (crates/biome_js_formatter/CONTRIBUTING.md)
crates/biome_js_formatter/**/*.rs: Implement theFormattrait for your node type and useJsFormatterwithwrite!/format_args!to define formatting
Import and use theFormatNodetrait for AST nodes
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
For non-mandatory tokens, use the provided helper constructors (e.g.,token,space_token,dynamic_token)
Do not attempt to fix code; if a mandatory token/node is missing, returnNoneinstead
Usedbg_write!to debug and inspect the emitted IR during formatting
Files:
crates/biome_js_formatter/src/utils/test_each_template.rscrates/biome_js_formatter/src/ts/types/bigint_literal_type.rscrates/biome_js_formatter/src/js/expressions/bigint_literal_expression.rscrates/biome_js_formatter/src/utils/jsx.rscrates/biome_js_formatter/src/comments.rscrates/biome_js_formatter/src/verbatim.rs
crates/biome_formatter/src/**/*.rs
📄 CodeRabbit inference engine (crates/biome_formatter/CONTRIBUTING.md)
After generation, remove usages of
format_verbatim_nodeand implement real formatting with biome_formatter utilities
Files:
crates/biome_formatter/src/macros.rscrates/biome_formatter/src/printer/mod.rscrates/biome_formatter/src/format_element/document.rscrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/lib.rscrates/biome_formatter/src/builders.rscrates/biome_formatter/src/format_extensions.rs
crates/biome_formatter/src/lib.rs
📄 CodeRabbit inference engine (crates/biome_formatter/CONTRIBUTING.md)
crates/biome_formatter/src/lib.rs: Add the provided AsFormat, IntoFormat, and iterator plumbing code to lib.rs
Implement FormatLanguage for HtmlFormatLanguage with associated types: SyntaxLanguage=HtmlLanguage, Context=HtmlFormatContext, FormatRule=FormatHtmlSyntaxNode
Define the HtmlFormatter type alias:type HtmlFormatter<'buf> = Formatter<'buf, HtmlFormatContext>;
Expose a documented public functionformat_node(options: HtmlFormatOptions, root: &HtmlSyntaxNode) -> FormatResult<Formatted<HtmlFormatContext>>delegating tobiome_formatter::format_node
Files:
crates/biome_formatter/src/lib.rs
🧠 Learnings (33)
📓 Common learnings
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
📚 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_css_formatter/src/css/value/url_value_raw.rscrates/biome_grit_formatter/src/verbatim.rscrates/biome_js_formatter/src/utils/test_each_template.rscrates/biome_js_formatter/src/ts/types/bigint_literal_type.rscrates/biome_css_formatter/src/verbatim.rscrates/biome_html_formatter/src/verbatim.rscrates/biome_html_formatter/src/utils/formatters.rscrates/biome_graphql_formatter/src/comments.rscrates/biome_jsdoc_comment/src/format_jsdoc_comment.rscrates/biome_js_formatter/src/js/expressions/bigint_literal_expression.rscrates/biome_json_formatter/src/comments.rscrates/biome_graphql_formatter/src/verbatim.rscrates/biome_css_formatter/src/lib.rscrates/biome_graphql_formatter/src/graphql/value/string_value.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_css_formatter/src/comments.rscrates/biome_grit_formatter/src/comments.rscrates/biome_js_formatter/src/utils/jsx.rscrates/biome_js_formatter/src/comments.rscrates/biome_html_formatter/src/utils/children.rscrates/biome_json_formatter/src/verbatim.rscrates/biome_css_semantic/src/format_semantic_model.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_js_formatter/src/verbatim.rscrates/biome_formatter/src/macros.rscrates/biome_module_graph/src/format_module_graph.rscrates/biome_formatter/src/format_element/document.rscrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/lib.rscrates/biome_formatter/src/builders.rscrates/biome_css_formatter/src/utils/string_utils.rscrates/biome_formatter/src/format_extensions.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_css_formatter/src/css/value/url_value_raw.rscrates/biome_grit_formatter/src/verbatim.rscrates/biome_js_formatter/src/utils/test_each_template.rscrates/biome_js_formatter/src/ts/types/bigint_literal_type.rscrates/biome_css_formatter/src/verbatim.rscrates/biome_html_formatter/src/verbatim.rscrates/biome_html_formatter/src/utils/formatters.rscrates/biome_graphql_formatter/src/comments.rscrates/biome_js_formatter/src/js/expressions/bigint_literal_expression.rscrates/biome_json_formatter/src/comments.rscrates/biome_graphql_formatter/src/verbatim.rscrates/biome_css_formatter/src/lib.rscrates/biome_graphql_formatter/src/graphql/value/string_value.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_css_formatter/src/comments.rscrates/biome_grit_formatter/src/comments.rscrates/biome_js_formatter/src/utils/jsx.rscrates/biome_js_formatter/src/comments.rscrates/biome_html_formatter/src/utils/children.rscrates/biome_json_formatter/src/verbatim.rscrates/biome_css_semantic/src/format_semantic_model.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_js_formatter/src/verbatim.rscrates/biome_formatter/src/macros.rscrates/biome_formatter/src/printer/mod.rscrates/biome_module_graph/src/format_module_graph.rscrates/biome_formatter/src/format_element/document.rs.changeset/real-tires-move.mdcrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/lib.rscrates/biome_formatter/src/builders.rscrates/biome_css_formatter/src/utils/string_utils.rscrates/biome_formatter/src/format_extensions.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_formatter/src/utils/test_each_template.rscrates/biome_css_formatter/src/verbatim.rscrates/biome_html_formatter/src/verbatim.rscrates/biome_html_formatter/src/utils/formatters.rscrates/biome_graphql_formatter/src/comments.rscrates/biome_js_formatter/src/js/expressions/bigint_literal_expression.rscrates/biome_graphql_formatter/src/verbatim.rscrates/biome_css_formatter/src/lib.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_css_formatter/src/comments.rscrates/biome_js_formatter/src/utils/jsx.rscrates/biome_html_formatter/src/utils/children.rscrates/biome_json_formatter/src/verbatim.rscrates/biome_css_semantic/src/format_semantic_model.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_formatter/src/printer/mod.rscrates/biome_module_graph/src/format_module_graph.rscrates/biome_formatter/src/format_element/document.rscrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/builders.rscrates/biome_css_formatter/src/utils/string_utils.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 : Import and use the `FormatNode` trait for AST nodes
Applied to files:
crates/biome_js_formatter/src/utils/test_each_template.rscrates/biome_js_formatter/src/ts/types/bigint_literal_type.rscrates/biome_css_formatter/src/verbatim.rscrates/biome_html_formatter/src/verbatim.rscrates/biome_html_formatter/src/utils/formatters.rscrates/biome_graphql_formatter/src/comments.rscrates/biome_jsdoc_comment/src/format_jsdoc_comment.rscrates/biome_js_formatter/src/js/expressions/bigint_literal_expression.rscrates/biome_json_formatter/src/comments.rscrates/biome_graphql_formatter/src/verbatim.rscrates/biome_css_formatter/src/lib.rscrates/biome_graphql_formatter/src/graphql/value/string_value.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_css_formatter/src/comments.rscrates/biome_js_formatter/src/utils/jsx.rscrates/biome_js_formatter/src/comments.rscrates/biome_html_formatter/src/utils/children.rscrates/biome_json_formatter/src/verbatim.rscrates/biome_css_semantic/src/format_semantic_model.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_formatter/src/printer/mod.rscrates/biome_module_graph/src/format_module_graph.rscrates/biome_formatter/src/format_element/document.rs.changeset/real-tires-move.mdcrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/lib.rscrates/biome_formatter/src/builders.rscrates/biome_css_formatter/src/utils/string_utils.rscrates/biome_formatter/src/format_extensions.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_js_formatter/src/utils/test_each_template.rscrates/biome_css_formatter/src/verbatim.rscrates/biome_html_formatter/src/utils/formatters.rscrates/biome_js_formatter/src/js/expressions/bigint_literal_expression.rscrates/biome_css_formatter/src/lib.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_css_formatter/src/comments.rscrates/biome_js_formatter/src/utils/jsx.rscrates/biome_json_formatter/src/verbatim.rscrates/biome_js_formatter/src/verbatim.rscrates/biome_formatter/src/format_element/document.rscrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/lib.rscrates/biome_formatter/src/builders.rscrates/biome_css_formatter/src/utils/string_utils.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_formatter/src/ts/types/bigint_literal_type.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_formatter/src/format_extensions.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_js_formatter/src/ts/types/bigint_literal_type.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_js_formatter/src/comments.rscrates/biome_css_semantic/src/format_semantic_model.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_module_graph/src/format_module_graph.rscrates/biome_formatter/src/format_extensions.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_html_formatter/src/verbatim.rscrates/biome_jsdoc_comment/src/format_jsdoc_comment.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_js_formatter/src/utils/jsx.rscrates/biome_html_formatter/src/utils/children.rscrates/biome_json_formatter/src/verbatim.rscrates/biome_css_semantic/src/format_semantic_model.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_formatter/src/printer/mod.rscrates/biome_module_graph/src/format_module_graph.rscrates/biome_formatter/src/format_element/document.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_html_formatter/src/verbatim.rscrates/biome_html_formatter/src/utils/formatters.rscrates/biome_jsdoc_comment/src/format_jsdoc_comment.rscrates/biome_css_formatter/src/lib.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_js_formatter/src/utils/jsx.rscrates/biome_html_formatter/src/utils/children.rscrates/biome_json_formatter/src/verbatim.rscrates/biome_css_semantic/src/format_semantic_model.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_formatter/src/printer/mod.rscrates/biome_module_graph/src/format_module_graph.rscrates/biome_formatter/src/format_element/document.rscrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/builders.rscrates/biome_css_formatter/src/utils/string_utils.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_html_formatter/src/verbatim.rscrates/biome_jsdoc_comment/src/format_jsdoc_comment.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_js_formatter/src/utils/jsx.rscrates/biome_html_formatter/src/utils/children.rscrates/biome_json_formatter/src/verbatim.rscrates/biome_css_semantic/src/format_semantic_model.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_module_graph/src/format_module_graph.rscrates/biome_formatter/src/format_element/document.rscrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/builders.rscrates/biome_css_formatter/src/utils/string_utils.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_html_formatter/src/utils/formatters.rscrates/biome_graphql_formatter/src/comments.rscrates/biome_jsdoc_comment/src/format_jsdoc_comment.rscrates/biome_json_formatter/src/comments.rscrates/biome_css_formatter/src/lib.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_css_formatter/src/comments.rscrates/biome_grit_formatter/src/comments.rscrates/biome_js_formatter/src/utils/jsx.rscrates/biome_js_formatter/src/comments.rscrates/biome_html_formatter/src/utils/children.rscrates/biome_json_formatter/src/verbatim.rscrates/biome_css_semantic/src/format_semantic_model.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_formatter/src/printer/mod.rscrates/biome_module_graph/src/format_module_graph.rscrates/biome_formatter/src/format_element/document.rscrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/lib.rscrates/biome_formatter/src/builders.rscrates/biome_css_formatter/src/utils/string_utils.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 : Add the provided AsFormat, IntoFormat, and iterator plumbing code to lib.rs
Applied to files:
crates/biome_html_formatter/src/utils/formatters.rscrates/biome_graphql_formatter/src/comments.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_css_formatter/src/comments.rscrates/biome_js_formatter/src/comments.rscrates/biome_css_semantic/src/format_semantic_model.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_module_graph/src/format_module_graph.rscrates/biome_formatter/src/format_element/document.rscrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/lib.rscrates/biome_formatter/src/builders.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_html_formatter/src/utils/formatters.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_html_formatter/src/utils/children.rscrates/biome_css_semantic/src/format_semantic_model.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_formatter/src/macros.rscrates/biome_formatter/src/format_element/document.rscrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/lib.rscrates/biome_css_formatter/src/utils/string_utils.rscrates/biome_formatter/src/format_extensions.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_html_formatter/src/utils/formatters.rscrates/biome_graphql_formatter/src/comments.rscrates/biome_jsdoc_comment/src/format_jsdoc_comment.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_css_formatter/src/comments.rscrates/biome_js_formatter/src/utils/jsx.rscrates/biome_html_formatter/src/utils/children.rscrates/biome_json_formatter/src/verbatim.rscrates/biome_css_semantic/src/format_semantic_model.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_module_graph/src/format_module_graph.rscrates/biome_formatter/src/format_element/document.rscrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/lib.rscrates/biome_css_formatter/src/utils/string_utils.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/comments.rs : Define HtmlCommentStyle implementing CommentStyle in comments.rs
Applied to files:
crates/biome_graphql_formatter/src/comments.rscrates/biome_jsdoc_comment/src/format_jsdoc_comment.rscrates/biome_json_formatter/src/comments.rscrates/biome_css_formatter/src/comments.rscrates/biome_grit_formatter/src/comments.rscrates/biome_js_formatter/src/comments.rscrates/biome_html_formatter/src/utils/children.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/comments.rs : Expose a public HtmlComments type alias: `pub type HtmlComments = Comments<HtmlLanguage>;`
Applied to files:
crates/biome_graphql_formatter/src/comments.rscrates/biome_jsdoc_comment/src/format_jsdoc_comment.rscrates/biome_json_formatter/src/comments.rscrates/biome_css_formatter/src/comments.rscrates/biome_js_formatter/src/comments.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 : Use `dbg_write!` to debug and inspect the emitted IR during formatting
Applied to files:
crates/biome_graphql_formatter/src/comments.rscrates/biome_jsdoc_comment/src/format_jsdoc_comment.rscrates/biome_js_type_info/src/format_type_info.rscrates/biome_js_formatter/src/utils/jsx.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_module_graph/src/format_module_graph.rscrates/biome_formatter/src/format_element/document.rscrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/builders.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}.rs : When inference is missing or cannot determine a type, use TypeData::Unknown; use TypeData::UnknownKeyword only when the user explicitly wrote unknown.
Applied to files:
crates/biome_js_type_info/src/format_type_info.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/biome_module_graph/src/js_module_info/collector.rs : Thin (module-level) inference should resolve local and global bindings to TypeReference::Resolved, mark imported bindings as TypeReference::Import, and fall back to TypeReference::Unknown if unresolved.
Applied to files:
crates/biome_js_type_info/src/format_type_info.rscrates/biome_module_graph/src/format_module_graph.rs
📚 Learning: 2025-08-20T16:24:59.781Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.
Applied to files:
crates/biome_js_type_info/src/format_type_info.rs
📚 Learning: 2025-10-03T12:28:56.788Z
Learnt from: ematipico
Repo: biomejs/biome PR: 7670
File: crates/biome_service/src/file_handlers/html.rs:744-748
Timestamp: 2025-10-03T12:28:56.788Z
Learning: In Biome's codebase, when creating tokens with new text content, use the factory pattern with functions like `ident(text)` from the respective `*_factory` crates (e.g., `biome_html_factory::make::ident`). There is no `.with_text()` method on tokens. The `ident()` function creates a new detached token with the IDENT kind, which is the standard approach for token construction.
Applied to files:
crates/biome_js_type_info/src/format_type_info.rscrates/biome_js_semantic/src/format_semantic_model.rscrates/biome_formatter/src/format_element.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 : Define the HtmlFormatter type alias: `type HtmlFormatter<'buf> = Formatter<'buf, HtmlFormatContext>;`
Applied to files:
crates/biome_js_type_info/src/format_type_info.rscrates/biome_html_formatter/src/utils/children.rscrates/biome_module_graph/src/format_module_graph.rscrates/biome_formatter/src/format_element/document.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_css_semantic/src/format_semantic_model.rscrates/biome_formatter/src/macros.rscrates/biome_formatter/src/format_element/document.rscrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/lib.rscrates/biome_formatter/src/format_extensions.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_css_semantic/src/format_semantic_model.rscrates/biome_formatter/src/format_element.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: The formatter relies on two pillars: implementing `Format`/`FormatNode` for nodes and creating an intermediate IR via helpers
Applied to files:
crates/biome_css_semantic/src/format_semantic_model.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_css_semantic/src/format_semantic_model.rscrates/biome_formatter/src/format_element/document.rscrates/biome_formatter/src/format_element.rscrates/biome_formatter/src/lib.rscrates/biome_formatter/src/format_extensions.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_css_semantic/src/format_semantic_model.rscrates/biome_formatter/src/format_element/document.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_css_semantic/src/format_semantic_model.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: Lexer must implement the biome_parser::Lexer trait
Applied to files:
crates/biome_css_semantic/src/format_semantic_model.rscrates/biome_formatter/src/format_element.rs
📚 Learning: 2025-09-13T16:16:06.459Z
Learnt from: ematipico
Repo: biomejs/biome PR: 7467
File: crates/biome_service/src/file_handlers/html.rs:456-466
Timestamp: 2025-09-13T16:16:06.459Z
Learning: In biome_formatter, the printer correctly handles consecutive LineMode::Hard elements without creating extra blank lines. Multiple consecutive FormatElement::Line(LineMode::Hard) elements in the formatting code do not result in duplicate blank lines in the output because the printer has logic to track line states and handle indentation properly.
Applied to files:
crates/biome_formatter/src/printer/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/biome_module_graph/src/**/*.rs : Do not copy or clone data between module graph entries (including behind Arc). Each module must avoid holding duplicated data from another module to enable simple invalidation.
Applied to files:
crates/biome_module_graph/src/format_module_graph.rs
📚 Learning: 2025-09-13T16:16:06.459Z
Learnt from: ematipico
Repo: biomejs/biome PR: 7467
File: crates/biome_service/src/file_handlers/html.rs:456-466
Timestamp: 2025-09-13T16:16:06.459Z
Learning: In biome_formatter, consecutive LineMode::Hard elements are automatically collapsed to a single newline by the printer. The printer has a test "it_prints_consecutive_hard_lines_as_one" that demonstrates this behavior - multiple consecutive hard line breaks result in only one newline in the output, not extra blank lines.
Applied to files:
crates/biome_formatter/src/format_element.rs
🔇 Additional comments (37)
crates/biome_jsdoc_comment/src/format_jsdoc_comment.rs (1)
17-17: LGTM! Clean adaptation to the new text() API.The change from
TextSize::default()toNoneis appropriate for JSDoc comment formatting where specific position tracking isn't required.crates/biome_html_formatter/src/utils/children.rs (1)
66-70: LGTM! Core refactoring correctly implemented.Source position is now emitted separately via
source_position().fmt()before the token text, removing the need for thesource_positionfield inLocatedTokenText. This aligns perfectly with the PR's architectural goal.crates/biome_js_formatter/src/utils/test_each_template.rs (1)
321-321: LGTM! Position tracking preserved correctly.The position argument is now wrapped in
Some(...), maintaining the same position tracking whilst adapting to the new Optional API.crates/biome_json_formatter/src/verbatim.rs (1)
119-119: LGTM! Verbatim formatting adapted correctly.Position is now wrapped in
Some(...), maintaining source mapping for verbatim nodes.crates/biome_html_formatter/src/utils/formatters.rs (1)
30-30: LGTM! Token replacement position preserved.The token's start position is correctly wrapped in
Some(...)for the replacement text.crates/biome_js_formatter/src/ts/types/bigint_literal_type.rs (1)
29-29: LGTM! BigInt literal formatting updated correctly.Position tracking maintained when converting to lowercase.
crates/biome_grit_formatter/src/verbatim.rs (1)
120-120: LGTM! Grit verbatim formatting aligned with other formatters.Consistent with the pattern used across all verbatim formatters.
crates/biome_js_formatter/src/comments.rs (2)
43-43: LGTM! Comment position tracking preserved.Source offsets for alignable comments are now wrapped in
Some(...), maintaining correct positioning for multiline comment alignment.
57-57: LGTM! Subsequent lines handled consistently.Each line in the multiline comment maintains its position tracking through
Some(source_offset).crates/biome_graphql_formatter/src/verbatim.rs (1)
118-122: LGTM!Position correctly wrapped with
Some()to match the updatedtext()signature.crates/biome_html_formatter/src/verbatim.rs (1)
142-146: LGTM!Consistent with the refactoring—position wrapped with
Some().crates/biome_graphql_formatter/src/comments.rs (1)
24-58: LGTM!Both
text()calls correctly updated to passSome(source_offset).crates/biome_js_formatter/src/utils/jsx.rs (1)
421-428: LGTM!Source position now emitted separately before
LocatedTokenText—this properly decouples position tracking from the text element.crates/biome_js_formatter/src/js/expressions/bigint_literal_expression.rs (1)
26-33: LGTM!Position correctly wrapped with
Some().crates/biome_json_formatter/src/comments.rs (1)
26-59: LGTM!Both
text()calls correctly updated withSome(source_offset).crates/biome_grit_formatter/src/comments.rs (1)
46-84: LGTM!Both
text()calls correctly updated withSome(source_offset).crates/biome_module_graph/src/format_module_graph.rs (5)
67-94: LGTM!Using
Nonefor synthetic formatting is correct, and thejoiner.finish()call properly completes the formatting.
205-259: LGTM!All
text()calls correctly updated to useNonefor synthetic content.
291-314: LGTM!Correct usage of
Nonefor synthetic text formatting.
317-348: LGTM!Consistent use of
Nonefor synthetic text.
97-131: Verify the control flow change.Line 129 now returns
Ok(())directly, whereasExports::fmtcallsjoiner.finish(). Should this also calljoiner.finish()for consistency?crates/biome_js_type_info/src/format_type_info.rs (2)
5-11: LGTM! Import reorganisation aligns with new API.The addition of explicit
format_argsandwriteimports supports the updatedtext()calls throughout the file.
98-1038: Consistent refactor to optional text positions.All
text()calls have been updated to useNonefor positions (replacingTextSize::default()or previously omitted positions). This mechanical change aligns perfectly with the PR's objective to separate source position tracking from text elements.crates/biome_js_formatter/src/verbatim.rs (1)
118-121: Position wrapped correctly for verbatim formatting.The concrete start position is now properly wrapped in
Some(), maintaining source mapping for verbatim nodes whilst conforming to the new optional position API.crates/biome_formatter/src/lib.rs (1)
1139-1163: Documentation updated to reflect new API.The example now demonstrates the preferred pattern of using
Nonefor text positions, keeping the documentation current with the API changes.crates/biome_js_semantic/src/format_semantic_model.rs (2)
2-2: Import additions support updated API usage.
108-182: Semantic model formatting updated consistently.All
text()calls now useNonefor positions, replacing the previousTextSize::default(). The semantic model display logic remains unchanged whilst adopting the new optional position API.crates/biome_formatter/src/macros.rs (1)
387-403: Test updated to match new text position API.The test now uses
Noneinstead ofTextSize::default(), ensuring test compatibility with the refactored API whilst maintaining the same test behaviour.crates/biome_css_formatter/src/css/value/url_value_raw.rs (1)
12-21: URL value position correctly wrapped.The concrete start position is now wrapped in
Some(), preserving source mapping for URL value tokens whilst conforming to the new optional position API.crates/biome_css_formatter/src/comments.rs (1)
29-62: Doc comment formatting positions preserved.Both
text()calls now wrapsource_offsetwithSome(), maintaining accurate source position tracking for doc comment lines whilst adopting the new optional position API.crates/biome_css_formatter/src/verbatim.rs (1)
117-121: Verbatim node position wrapped correctly.The concrete start position is now properly wrapped in
Some(), maintaining source mapping for CSS verbatim nodes whilst conforming to the new optional position API.crates/biome_formatter/src/printer/mod.rs (3)
142-148: LGTM – clean deferral mechanism.The source position queuing avoids the indent-mapping issue mentioned in the comments. Well thought through.
319-397: Deferral logic correctly implemented.The pending position is consumed at text emission time, source_position is advanced appropriately, and markers are emitted at the right boundaries. The refactoring achieves the stated goal of preventing enum bloat.
1160-1162: Correct to ignore SourcePosition during fits checking.Source position tracking doesn't affect layout decisions. The explicit handling avoids unintended side effects.
crates/biome_formatter/src/builders.rs (3)
278-331: Well-designed source position helper.The deduplication logic (lines 321–325) avoids redundant consecutive SourcePosition elements in the IR. Documentation is clear with good examples.
334-355: API change correctly implemented.The
Option<TextSize>parameter allows formatter-generated text (None) to be distinguished from source text (Some). The Format impl correctly uses thesource_position()helper for deduplication.
382-404: Correct usage of the source_position helper.Line 384 properly delegates to the helper, ensuring IR-level deduplication applies here as well.
| } | ||
| } | ||
|
|
||
| if source_position.is_some() { |
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.
I guess it isn’t 100% correct to use text_len to calculate the source position of the second marker, because the text can be modified during formatting. However, if it doesn’t produce an error, I think it’s better to keep it as is.
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.
This isn't really a user facing change, so this doesn't need a changeset.
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.
We could if we manage to increase the performance of the formatter
|
I don't know why, but the benchmarks are weird. If you open the dashboard, you'll see improvements up to 6% too. |
I guess the degradation makes sense, we now spend more time on allocation because we’re pushing extra elements. But I'm not sure about the improvement part, since we removed source_position to make room for text_width, yet the total layout size is still 24 because of padding, right? |
|
I wonder if we can remove the |
Summary
We need to optimize the memory layout of the FormatElement enum to store the text size within the element; otherwise, it exceeds 24 bytes.
#7983
Test Plan
Green CI
Docs