Skip to content

feat(format/yaml): flow collection blank lines and spacing - #11064

Merged
dyc3 merged 4 commits into
mainfrom
dyc3/yaml-fmt-flow-spacing
Jul 29, 2026
Merged

feat(format/yaml): flow collection blank lines and spacing#11064
dyc3 merged 4 commits into
mainfrom
dyc3/yaml-fmt-flow-spacing

Conversation

@dyc3

@dyc3 dyc3 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

fixes a bunch of spacing/blank-line quirks in flow context

implemented by fable 5

Test Plan

updated snapshots

Docs

@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ddef529

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

@github-actions

Copy link
Copy Markdown
Contributor

✅ Organic activity

No automation signals detected in the analyzed events.

View full analysis →

This is an automated analysis by AgentScan

@github-actions github-actions Bot added A-Formatter Area: formatter L-Yaml Language: Yaml labels Jul 23, 2026
@dyc3
dyc3 force-pushed the dyc3/yaml-fmt-flow-spacing branch from 69ce2d4 to a90cbe7 Compare July 25, 2026 19:48
@dyc3
dyc3 marked this pull request as ready for review July 25, 2026 19:51
Comment thread crates/biome_yaml_formatter/src/utils.rs Outdated
Comment thread crates/biome_yaml_formatter/src/comments.rs Outdated
@dyc3
dyc3 force-pushed the dyc3/yaml-fmt-flow-spacing branch 2 times, most recently from 3c84655 to f869e74 Compare July 27, 2026 11:57
Base automatically changed from dyc3/yaml-fmt-middle-comments to main July 28, 2026 20:17
dyc3 and others added 4 commits July 28, 2026 16:18
Blank lines between flow entries now survive only when the collection
breaks: they print as literal line breaks behind if_group_breaks, so
they no longer force `{ a,\n\nb }` to expand. A comment right after
the opening bracket on a mapping key's line ends that line, as
Prettier treats it. Also matches Prettier's spacing quirks: `[ : ]`
becomes `[: ]`, a tag with empty content keeps its separating space
(`{ foo: !!str , ... }`), and an empty sequence entry with an inline
comment gets a double space (`-  # comment`).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01472YxeN6U2t4LWfaqkieAv
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017JxH5Z1zv28qj1CcHABVee
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017JxH5Z1zv28qj1CcHABVee
@dyc3
dyc3 force-pushed the dyc3/yaml-fmt-flow-spacing branch from f869e74 to ddef529 Compare July 28, 2026 20:19
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Updates YAML comment placement for flow collections beginning on mapping key lines. Adds spacing for empty block and flow entries, preserves separators and blank lines in flow collections, and updates YAML fixtures covering empty entries and collapsed or retained empty lines.

Possibly related PRs

Suggested reviewers: ematipico, siketyan

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly reflects the main YAML formatter change around flow collection blank lines and spacing.
Description check ✅ Passed The description matches the PR and mentions fixing spacing and blank-line quirks in flow context.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dyc3/yaml-fmt-flow-spacing

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

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/biome_yaml_formatter/src/comments.rs`:
- Around line 159-162: Update the on_key_line calculation in the
comment-handling logic to require enclosing to be the immediate mapping value,
replacing the ancestor-wide match that also accepts nested flow collections.
Preserve the existing line-token condition, and add a regression test covering a
comment after an inner opening bracket to ensure it is not moved to the outer
mapping key.

In `@crates/biome_yaml_formatter/src/yaml/auxiliary/block_sequence_entry.rs`:
- Around line 14-24: Add snapshot coverage for the formatter branches in
crates/biome_yaml_formatter/src/yaml/auxiliary/block_sequence_entry.rs:14-24 by
adding a block-sequence “- # comment” fixture, and in
crates/biome_yaml_formatter/src/yaml/lists/flow_map_entry_list.rs:22-36 by
adding both collapsed and expanded blank-line flow-mapping cases. Ensure the
snapshots cover the relevant valid and invalid formatter inputs.
🪄 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: 2bd0cdd8-0c2e-499e-a03a-e062c53bc645

📥 Commits

Reviewing files that changed from the base of the PR and between 61e35a3 and ddef529.

⛔ Files ignored due to path filters (8)
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/flow-mapping/empty-line-collapse.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/flow-sequence/empty-item-colon.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/flow-sequence/empty-line-collapse.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-6-1-indentation-spaces.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-7-2-empty-content.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-8-15-block-sequence-entry-types.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/yaml/flow/empty_entries.yaml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/yaml/flow/flow_sequence_formatting.yaml.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (9)
  • crates/biome_yaml_formatter/src/comments.rs
  • crates/biome_yaml_formatter/src/utils.rs
  • crates/biome_yaml_formatter/src/yaml/auxiliary/block_sequence_entry.rs
  • crates/biome_yaml_formatter/src/yaml/auxiliary/flow_map_implicit_entry.rs
  • crates/biome_yaml_formatter/src/yaml/auxiliary/flow_yaml_node.rs
  • crates/biome_yaml_formatter/src/yaml/lists/flow_map_entry_list.rs
  • crates/biome_yaml_formatter/src/yaml/lists/flow_sequence_entry_list.rs
  • crates/biome_yaml_formatter/tests/specs/yaml/flow/empty_entries.yaml
  • crates/biome_yaml_formatter/tests/specs/yaml/flow/flow_sequence_formatting.yaml

Comment on lines +159 to +162
let on_key_line = enclosing
.ancestors()
.any(|ancestor| ancestor == *value.syntax())
&& lines_before_through_end_tokens(value.syntax()) == 0;

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Restrict this to the immediate mapping value.

ancestors().any(...) also matches nested flow collections, so a comment after an inner opening bracket can be moved to the outer mapping key. Require direct containment instead, and add a nested regression case.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/biome_yaml_formatter/src/comments.rs` around lines 159 - 162, Update
the on_key_line calculation in the comment-handling logic to require enclosing
to be the immediate mapping value, replacing the ancestor-wide match that also
accepts nested flow collections. Preserve the existing line-token condition, and
add a regression test covering a comment after an inner opening bracket to
ensure it is not moved to the outer mapping key.

Comment on lines +14 to +24
// An entry without a value but with a comment on its line still gets
// the space that would separate the value from the `-`, so the
// comment ends up two columns over: `- # comment`
if value.is_none()
&& f.comments()
.dangling_comments(node.syntax())
.first()
.is_some_and(|comment| comment.lines_before() == 0)
{
write!(f, [text(" ", None)])?;
}

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add snapshots for these unexercised formatter branches.

  • crates/biome_yaml_formatter/src/yaml/auxiliary/block_sequence_entry.rs#L14-L24: add a block sequence - # comment fixture.
  • crates/biome_yaml_formatter/src/yaml/lists/flow_map_entry_list.rs#L22-L36: add collapsed and expanded blank-line cases for a flow mapping.

As per coding guidelines, “All code changes must include appropriate tests”; formatter changes also require snapshot coverage for valid and invalid cases.

📍 Affects 2 files
  • crates/biome_yaml_formatter/src/yaml/auxiliary/block_sequence_entry.rs#L14-L24 (this comment)
  • crates/biome_yaml_formatter/src/yaml/lists/flow_map_entry_list.rs#L22-L36
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/biome_yaml_formatter/src/yaml/auxiliary/block_sequence_entry.rs`
around lines 14 - 24, Add snapshot coverage for the formatter branches in
crates/biome_yaml_formatter/src/yaml/auxiliary/block_sequence_entry.rs:14-24 by
adding a block-sequence “- # comment” fixture, and in
crates/biome_yaml_formatter/src/yaml/lists/flow_map_entry_list.rs:22-36 by
adding both collapsed and expanded blank-line flow-mapping cases. Ensure the
snapshots cover the relevant valid and invalid formatter inputs.

Source: Coding guidelines

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.

@dyc3 is this relevant?

@dyc3
dyc3 requested a review from ematipico July 29, 2026 01:13
Comment on lines +14 to +24
// An entry without a value but with a comment on its line still gets
// the space that would separate the value from the `-`, so the
// comment ends up two columns over: `- # comment`
if value.is_none()
&& f.comments()
.dangling_comments(node.syntax())
.first()
.is_some_and(|comment| comment.lines_before() == 0)
{
write!(f, [text(" ", None)])?;
}

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.

@dyc3 is this relevant?

@dyc3
dyc3 merged commit cba196d into main Jul 29, 2026
27 checks passed
@dyc3
dyc3 deleted the dyc3/yaml-fmt-flow-spacing branch July 29, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Formatter Area: formatter L-Yaml Language: Yaml

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants