feat(formatter): add delimiterSpacing option#9718
Conversation
Add the `delimiterSpacing` formatter option. This option inserts spaces inside delimiters when content fits on a single line. Empty delimiters are not affected, and no space is added before the opening delimiter. The specific delimiters affected depend on the language. Includes the shared DelimiterSpacing type, global configuration, overrides support, Prettier migration, CLI flag, generated schema/bindings, and changeset.
🦋 Changeset detectedLatest commit: 1505202 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 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 |
Merging this PR will not alter performance
Comparing Footnotes
|
WalkthroughA new 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/biome_cli/src/execute/migrate/prettier.rs (1)
230-239:⚠️ Potential issue | 🟠 MajorPropagate the migrated
bracket_spacingvalue here as well.The shared formatter initialiser hard-codes
bracket_spacingto default while the JavaScript formatter below uses the migrated value from Prettier config. A config withbracketSpacing: falsewill be migrated inconsistently and break for any language reading the shared formatter setting.Suggested fix
- bracket_spacing: Some(BracketSpacing::default()), + bracket_spacing: Some(value.bracket_spacing.into()), delimiter_spacing: None,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/biome_cli/src/execute/migrate/prettier.rs` around lines 230 - 239, The shared FormatterConfiguration currently hard-codes bracket_spacing to BracketSpacing::default(), causing inconsistent migration; update the bracket_spacing field in the FormatterConfiguration initializer to use the migrated Prettier value (the variable holding the migrated bracket spacing from the Prettier migration code—e.g., value.bracket_spacing or the local migrated_bracket_spacing) and wrap it with Some(...). Modify the FormatterConfiguration instantiation (symbol: FormatterConfiguration) so bracket_spacing: Some(<migrated value>.into()) or simply Some(<migrated value>) is used instead of BracketSpacing::default() to ensure the migrated setting is propagated.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.changeset/delimiter-spacing-option.md:
- Around line 1-5: The changeset text incorrectly presents the formatter option
"delimiterSpacing" as implemented; either wait to land this changeset until the
JS/CSS/JSON formatter implementations are merged, or update the changeset
description to clearly state this is groundwork only and the option is currently
a no-op (keep the default false and the config keys
javascript.formatter.delimiterSpacing, json.formatter.delimiterSpacing,
css.formatter.delimiterSpacing unchanged). Make a concise edit to the changeset
content so it does not promise runtime behavior until the consumer PRs
implementing delimiterSpacing are merged.
---
Outside diff comments:
In `@crates/biome_cli/src/execute/migrate/prettier.rs`:
- Around line 230-239: The shared FormatterConfiguration currently hard-codes
bracket_spacing to BracketSpacing::default(), causing inconsistent migration;
update the bracket_spacing field in the FormatterConfiguration initializer to
use the migrated Prettier value (the variable holding the migrated bracket
spacing from the Prettier migration code—e.g., value.bracket_spacing or the
local migrated_bracket_spacing) and wrap it with Some(...). Modify the
FormatterConfiguration instantiation (symbol: FormatterConfiguration) so
bracket_spacing: Some(<migrated value>.into()) or simply Some(<migrated value>)
is used instead of BracketSpacing::default() to ensure the migrated setting is
propagated.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e70a61c6-2ac8-4050-b21b-451c5cb713bf
⛔ Files ignored due to path filters (7)
crates/biome_cli/tests/snapshots/main_cases_help/check_help.snapis excluded by!**/*.snapand included by**crates/biome_cli/tests/snapshots/main_cases_help/ci_help.snapis excluded by!**/*.snapand included by**crates/biome_cli/tests/snapshots/main_cases_help/format_help.snapis excluded by!**/*.snapand included by**crates/biome_configuration/tests/invalid/formatter_extraneous_field.json.snapis excluded by!**/*.snapand included by**crates/biome_configuration/tests/invalid/formatter_quote_style.json.snapis excluded by!**/*.snapand included by**packages/@biomejs/backend-jsonrpc/src/workspace.tsis excluded by!**/backend-jsonrpc/src/workspace.tsand included by**packages/@biomejs/biome/configuration_schema.jsonis excluded by!**/configuration_schema.jsonand included by**
📒 Files selected for processing (6)
.changeset/delimiter-spacing-option.mdcrates/biome_cli/src/execute/migrate/prettier.rscrates/biome_configuration/src/formatter.rscrates/biome_configuration/src/overrides.rscrates/biome_formatter/src/lib.rscrates/biome_service/src/settings.rs
| "@biomejs/biome": minor | ||
| --- | ||
|
|
||
| Added the `delimiterSpacing` formatter option. This option inserts spaces inside delimiters (after the opening delimiter and before the closing delimiter) when the content fits on a single line. Empty delimiters are not affected, and no space is added before the opening delimiter. The specific delimiters affected depend on the language. It can be configured globally via `formatter.delimiterSpacing` or per-language via `javascript.formatter.delimiterSpacing`, `json.formatter.delimiterSpacing`, and `css.formatter.delimiterSpacing`. Defaults to false. |
There was a problem hiding this comment.
I won't block the PR now, but consider improving the changeset in the other PRs by showing some code blocks using the diff code block .e.g
```diff
- callFn(foo)
+ callFn( foo )
```
There was a problem hiding this comment.
All the other PRs already have small diffs.
There was a problem hiding this comment.
Ok, but at the end we should have only one changset, because that's one single (big) feature
There was a problem hiding this comment.
Oh, ok. I'll do that.
Huge kudos to @orballo for doing most of the work in discovering which parts of the Biome formatter needed to be changed to add this option in his proof of concept: orballo#1
Summary
This PR adds the
delimiterSpacingformatter option infrastructure. When enabled, it inserts spaces inside delimiters when the content fits on a single line. Empty delimiters are not affected, and no space is added before the opening delimiter. The specific delimiters affected depend on the language.See #2360 (comment).
This PR includes only the shared infrastructure:
DelimiterSpacingtype inbiome_formatterformatter.delimiterSpacing)--delimiter-spacing)Configuration example:
{ "formatter": { "delimiterSpacing": true } }The actual formatting behavior is implemented in follow-up PRs:
AI usage
As the Gutenberg project is using a non-official fork of Prettier, I ran @orballo's Biome version in the Gutenberg repository and used AI to extract all the tests and edge cases. Then AI assisted me in converting the changes made by @orballo's proof of concept to changes in the current formatter. AI also assisted in splitting the original PR into per-language PRs.
Test Plan
Website PR (needs to be updated with latest documentation changes)