Skip to content

chore(doc): update formatter contributing doc#8972

Merged
ematipico merged 4 commits intobiomejs:mainfrom
tidefield:update-formatter-contributing-doc
Feb 5, 2026
Merged

chore(doc): update formatter contributing doc#8972
ematipico merged 4 commits intobiomejs:mainfrom
tidefield:update-formatter-contributing-doc

Conversation

@tidefield
Copy link
Copy Markdown
Contributor

@tidefield tidefield commented Feb 5, 2026

I was working on #8962 and confused by the organization of the contributing doc. It hasn't been updated for a while.

The PR fixes and improves the readability to better reflect how the codegen actually works (for easier debugging if something is missing or has error) and what we need to implement manually.

Disclosure: I used AI to help putting up the improvement but I manually go through each step carefully to make sure it's readable.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 5, 2026

⚠️ No Changeset found

Latest commit: 60f2472

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@tidefield tidefield marked this pull request as ready for review February 5, 2026 09:39
@github-actions github-actions Bot added the A-Formatter Area: formatter label Feb 5, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 5, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

Replaces the manual, example-driven CONTRIBUTING.md for crates/biome_formatter with a codegen-first workflow. Documents a multi-step process: create a formatter crate, run the generator to produce boilerplate, inspect generated files (lib.rs, context.rs, comments.rs, cst.rs, prelude.rs, verbatim.rs, language modules, generated.rs), add required types, implement node-specific formatters, and run generated tests. Emphasises that the .ungram grammar remains the source of truth and that codegen maps grammar AST nodes to files and trait implementations. No public API changes.

Possibly related PRs

Suggested reviewers

  • arendjr
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: updating the formatter contribution documentation with improvements to reflect codegen workflows.
Description check ✅ Passed The description clearly relates to the changeset, explaining the motivation (outdated doc), the improvements made (clarifying codegen and manual implementation), and disclosure of AI assistance.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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: 2

🤖 Fix all issues with AI agents
In `@crates/biome_formatter/CONTRIBUTING.md`:
- Line 332: Change the phrase "Accept snapshots after verifying they're
correct:" in CONTRIBUTING.md to use the possessive pronoun; replace it with
"Accept snapshots after verifying their correctness:" so the sentence reads
correctly, updating the exact string found in the file.
- Line 15: Add a missing comma after "example" in the CONTRIBUTING.md sentence
that reads "The following steps refer to html as an example but it should be
mostly relevant for any language." to improve readability; locate the sentence
in CONTRIBUTING.md (the paragraph referencing "html as an example") and insert a
comma so it reads "html as an example, but it should be mostly relevant for any
language."

Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
}
}
}
The recommended way to add a formatter for a new language is to use provided codegen This automatically generates the boilerplate code based on the language's grammar. The following steps refer to html as an example but it should be mostly relevant for any language.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add the missing comma for readability.
“...as an example, but it should...” reads better and avoids the run‑on.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~15-~15: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...lowing steps refer to html as an example but it should be mostly relevant for any la...

(COMMA_COMPOUND_SENTENCE)

🤖 Prompt for AI Agents
In `@crates/biome_formatter/CONTRIBUTING.md` at line 15, Add a missing comma after
"example" in the CONTRIBUTING.md sentence that reads "The following steps refer
to html as an example but it should be mostly relevant for any language." to
improve readability; locate the sentence in CONTRIBUTING.md (the paragraph
referencing "html as an example") and insert a comma so it reads "html as an
example, but it should be mostly relevant for any language."

cargo t
```

Accept snapshots after verifying they're correct:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use “their” here.
“Accept snapshots after verifying their correctness” is the intended phrasing.

🧰 Tools
🪛 LanguageTool

[misspelling] ~332-~332: Did you mean “verifying their”?
Context: ...ell cargo t Accept snapshots after verifying they're correct: shell cargo insta accept `...

(VBG_THEYRE)

🤖 Prompt for AI Agents
In `@crates/biome_formatter/CONTRIBUTING.md` at line 332, Change the phrase
"Accept snapshots after verifying they're correct:" in CONTRIBUTING.md to use
the possessive pronoun; replace it with "Accept snapshots after verifying their
correctness:" so the sentence reads correctly, updating the exact string found
in the file.

Copy link
Copy Markdown
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First review, I'll continue later

This guide assumes the parser and grammar for your language are already implemented by following [the guidance](../biome_parser/CONTRIBUTING.md)

<summary>Code to copy</summary>
The formatter codegen depends on the generated AST types from the grammar, so you must complete the parser and grammar implementation before starting on the formatter.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid the acronym AST. Biome uses CST. Maybe use nodes/tokens or types

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about this as well. Why does the generated code refer to biome_rowan::AstNode though?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably poor naming convention from rowan. Or maybe because it's the red node, which "mimics" an AST like navigation with typed nodes.

Still, it's not an AST, because we have access to trivia.

Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
Comment thread crates/biome_formatter/CONTRIBUTING.md
Comment thread crates/biome_formatter/CONTRIBUTING.md
Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
Copy link
Copy Markdown
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: 2

🤖 Fix all issues with AI agents
In `@crates/biome_formatter/CONTRIBUTING.md`:
- Around line 240-242: Remove the stray leading punctuation character before the
first bullet in the list describing format traits and ensure consistent bullet
punctuation; specifically edit the list containing **AsFormat<Context>**,
**IntoFormat<Context>**, and **FormatRule<NodeType>** in CONTRIBUTING.md to
remove the odd character preceding the first bullet and make the bullets'
punctuation consistent (either remove terminal punctuation from all or add
periods to all).
- Around line 236-243: Update the trait name in the "Key traits created by
codegen" list from FormatRule<NodeType> to FormatNodeRule<NodeType]; mention
that codegen implements the FormatNodeRule<N> trait and that the required method
is fmt_fields while default implementations exist for fmt, is_suppressed,
fmt_leading_comments, fmt_dangling_comments, and fmt_trailing_comments to avoid
confusion for contributors.

Comment thread crates/biome_formatter/CONTRIBUTING.md
Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
Copy link
Copy Markdown
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

🤖 Fix all issues with AI agents
In `@crates/biome_formatter/CONTRIBUTING.md`:
- Line 314: The test command in CONTRIBUTING.md contains a typo: change the test
name invocation "html::simle_element" to "html::simple_element" so documentation
and test references match the actual test; update any occurrences of the
misspelled "simle_element" to "simple_element" (e.g., the example cargo test
invocation and any referenced test function names).

Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
@tidefield tidefield force-pushed the update-formatter-contributing-doc branch 3 times, most recently from 023e5f3 to d04b6f1 Compare February 5, 2026 14:47
Copy link
Copy Markdown
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

🤖 Fix all issues with AI agents
In `@crates/biome_formatter/CONTRIBUTING.md`:
- Around line 29-40: Change the CONTRIBUTING wording to state that the generator
produces node-specific implementations of the FormatNodeRule trait (e.g.,
FormatNodeRule<N>) rather than generic FormatRule implementations: explain that
generated impls implement FormatNodeRule<N> and must provide fmt_fields, while
fmt, is_suppressed, fmt_leading_comments, fmt_dangling_comments, and
fmt_trailing_comments have default implementations; update the bullet that
currently reads "Generates default `FormatRule` implementations" to mention
`FormatNodeRule<N>` and `fmt_fields` as the required method to reflect the
actual generated symbols.

Comment thread crates/biome_formatter/CONTRIBUTING.md
@tidefield tidefield force-pushed the update-formatter-contributing-doc branch 2 times, most recently from f23529d to fe90dc6 Compare February 5, 2026 14:57
Copy link
Copy Markdown
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great improvement. Thank you @tidefield for the enhancements!

@tidefield tidefield force-pushed the update-formatter-contributing-doc branch from fe90dc6 to e3eccb9 Compare February 5, 2026 15:07
Copy link
Copy Markdown
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

🤖 Fix all issues with AI agents
In `@crates/biome_formatter/CONTRIBUTING.md`:
- Around line 104-106: The example implements the wrong concrete type: replace
the impl block that reads impl FormatOptions for MarkdownFormatOptions with impl
FormatOptions for HtmlFormatOptions so the trait implementation matches the HTML
formatter context; update any example mentions of MarkdownFormatOptions to
HtmlFormatOptions to avoid the copy-paste mismatch for the FormatOptions trait.

Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
@tidefield tidefield force-pushed the update-formatter-contributing-doc branch 3 times, most recently from 6133bd5 to 45c28bd Compare February 5, 2026 15:22
@tidefield tidefield force-pushed the update-formatter-contributing-doc branch from 45c28bd to 4a4ddc6 Compare February 5, 2026 15:23
@tidefield
Copy link
Copy Markdown
Contributor Author

That's a great improvement. Thank you @tidefield for the enhancements!

My pleasure! As always, thanks for the thorough review. It helps me re-learn how things work once again.

Copy link
Copy Markdown
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

🤖 Fix all issues with AI agents
In `@crates/biome_formatter/CONTRIBUTING.md`:
- Line 333: The relative link text "../crates/biome_parser/CONTRIBUTING.md" in
the sentence about "Undefined node: AnyHtmlBlock" is incorrect; update that path
to "../biome_parser/CONTRIBUTING.md" to match the correct link used elsewhere
(see the existing correct reference at line 9) so the parser contributing guide
resolves properly.
🧹 Nitpick comments (1)
crates/biome_formatter/CONTRIBUTING.md (1)

159-179: Document the constructor for HtmlFormatLanguage.

The code at line 179 calls HtmlFormatLanguage::new(options), but the new method isn't shown in any of the earlier code examples. Contributors following this guide won't know how to implement it.

📋 Suggested addition after line 161
 pub struct HtmlFormatLanguage {
     options: HtmlFormatOptions,
 }
+
+impl HtmlFormatLanguage {
+    pub fn new(options: HtmlFormatOptions) -> Self {
+        Self { options }
+    }
+}

Comment thread crates/biome_formatter/CONTRIBUTING.md Outdated
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@ematipico ematipico merged commit 5a341b2 into biomejs:main Feb 5, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Formatter Area: formatter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants