Skip to content

feat(formatter): add delimiterSpacing option#9718

Merged
ematipico merged 1 commit into
biomejs:nextfrom
luisherranz:feat/delimiter-spacing-core
Apr 1, 2026
Merged

feat(formatter): add delimiterSpacing option#9718
ematipico merged 1 commit into
biomejs:nextfrom
luisherranz:feat/delimiter-spacing-core

Conversation

@luisherranz

@luisherranz luisherranz commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

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 delimiterSpacing formatter 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:

  • The DelimiterSpacing type in biome_formatter
  • Global configuration (formatter.delimiterSpacing)
  • Overrides support
  • Prettier migration compatibility
  • CLI flag (--delimiter-spacing)
  • Generated schema and bindings

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

  • Updated CLI help snapshots
  • Updated configuration validation snapshots

Website PR (needs to be updated with latest documentation changes)

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-bot

changeset-bot Bot commented Mar 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1505202

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@biomejs/biome Minor
@biomejs/cli-win32-x64 Minor
@biomejs/cli-win32-arm64 Minor
@biomejs/cli-darwin-x64 Minor
@biomejs/cli-darwin-arm64 Minor
@biomejs/cli-linux-x64 Minor
@biomejs/cli-linux-arm64 Minor
@biomejs/cli-linux-x64-musl Minor
@biomejs/cli-linux-arm64-musl Minor
@biomejs/wasm-web Minor
@biomejs/wasm-bundler Minor
@biomejs/wasm-nodejs Minor
@biomejs/backend-jsonrpc Patch
@biomejs/js-api Major

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

@codspeed-hq

codspeed-hq Bot commented Mar 31, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 168 skipped benchmarks1


Comparing luisherranz:feat/delimiter-spacing-core (1505202) with next (9ee64f8)

Open in CodSpeed

Footnotes

  1. 168 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@luisherranz luisherranz marked this pull request as ready for review March 31, 2026 11:21
@coderabbitai

coderabbitai Bot commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

A new delimiterSpacing formatter option has been added throughout the Biome codebase. A new DelimiterSpacing type is defined in the formatter crate, then integrated into configuration structures across multiple crates including formatter configuration, override configurations, and service settings. CLI support for the --delimiter-spacing true|false flag is added. The Prettier migration code is updated to explicitly set this field, and documentation of the option's behaviour is provided via a changeset entry.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding the delimiterSpacing formatter option across the codebase.
Description check ✅ Passed The PR description comprehensively explains the changes, including infrastructure components, configuration examples, follow-up PRs, and AI usage transparency.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

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.

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 | 🟠 Major

Propagate the migrated bracket_spacing value here as well.

The shared formatter initialiser hard-codes bracket_spacing to default while the JavaScript formatter below uses the migrated value from Prettier config. A config with bracketSpacing: false will 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9ee64f8 and 1505202.

⛔ Files ignored due to path filters (7)
  • crates/biome_cli/tests/snapshots/main_cases_help/check_help.snap is excluded by !**/*.snap and included by **
  • crates/biome_cli/tests/snapshots/main_cases_help/ci_help.snap is excluded by !**/*.snap and included by **
  • crates/biome_cli/tests/snapshots/main_cases_help/format_help.snap is excluded by !**/*.snap and included by **
  • crates/biome_configuration/tests/invalid/formatter_extraneous_field.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_configuration/tests/invalid/formatter_quote_style.json.snap is excluded by !**/*.snap and included by **
  • packages/@biomejs/backend-jsonrpc/src/workspace.ts is excluded by !**/backend-jsonrpc/src/workspace.ts and included by **
  • packages/@biomejs/biome/configuration_schema.json is excluded by !**/configuration_schema.json and included by **
📒 Files selected for processing (6)
  • .changeset/delimiter-spacing-option.md
  • crates/biome_cli/src/execute/migrate/prettier.rs
  • crates/biome_configuration/src/formatter.rs
  • crates/biome_configuration/src/overrides.rs
  • crates/biome_formatter/src/lib.rs
  • crates/biome_service/src/settings.rs

Comment thread .changeset/delimiter-spacing-option.md
"@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.

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 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 )
```

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.

All the other PRs already have small diffs.

@ematipico ematipico Apr 1, 2026

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.

Ok, but at the end we should have only one changset, because that's one single (big) feature

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.

Oh, ok. I'll do that.

@ematipico ematipico merged commit ca5be09 into biomejs:next Apr 1, 2026
30 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Formatter Area: formatter A-Project Area: project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants