feat(format/yaml): flow collection blank lines and spacing - #11064
Conversation
|
✅ Organic activityNo automation signals detected in the analyzed events. This is an automated analysis by AgentScan |
69ce2d4 to
a90cbe7
Compare
3c84655 to
f869e74
Compare
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 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
f869e74 to
ddef529
Compare
WalkthroughUpdates 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: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (8)
crates/biome_yaml_formatter/tests/specs/prettier/yaml/flow-mapping/empty-line-collapse.yml.snapis excluded by!**/*.snapand included by**crates/biome_yaml_formatter/tests/specs/prettier/yaml/flow-sequence/empty-item-colon.yml.snapis excluded by!**/*.snapand included by**crates/biome_yaml_formatter/tests/specs/prettier/yaml/flow-sequence/empty-line-collapse.yml.snapis excluded by!**/*.snapand included by**crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-6-1-indentation-spaces.yml.snapis excluded by!**/*.snapand included by**crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-7-2-empty-content.yml.snapis excluded by!**/*.snapand included by**crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-8-15-block-sequence-entry-types.yml.snapis excluded by!**/*.snapand included by**crates/biome_yaml_formatter/tests/specs/yaml/flow/empty_entries.yaml.snapis excluded by!**/*.snapand included by**crates/biome_yaml_formatter/tests/specs/yaml/flow/flow_sequence_formatting.yaml.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (9)
crates/biome_yaml_formatter/src/comments.rscrates/biome_yaml_formatter/src/utils.rscrates/biome_yaml_formatter/src/yaml/auxiliary/block_sequence_entry.rscrates/biome_yaml_formatter/src/yaml/auxiliary/flow_map_implicit_entry.rscrates/biome_yaml_formatter/src/yaml/auxiliary/flow_yaml_node.rscrates/biome_yaml_formatter/src/yaml/lists/flow_map_entry_list.rscrates/biome_yaml_formatter/src/yaml/lists/flow_sequence_entry_list.rscrates/biome_yaml_formatter/tests/specs/yaml/flow/empty_entries.yamlcrates/biome_yaml_formatter/tests/specs/yaml/flow/flow_sequence_formatting.yaml
| let on_key_line = enclosing | ||
| .ancestors() | ||
| .any(|ancestor| ancestor == *value.syntax()) | ||
| && lines_before_through_end_tokens(value.syntax()) == 0; |
There was a problem hiding this comment.
🎯 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.
| // 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)])?; | ||
| } |
There was a problem hiding this comment.
📐 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- # commentfixture.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
| // 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)])?; | ||
| } |
Summary
fixes a bunch of spacing/blank-line quirks in flow context
implemented by fable 5
Test Plan
updated snapshots
Docs