Skip to content

feat(format/yaml): flow scalar content - #11050

Merged
dyc3 merged 2 commits into
mainfrom
dyc3/yaml-fmt-flow-scalars
Jul 26, 2026
Merged

feat(format/yaml): flow scalar content#11050
dyc3 merged 2 commits into
mainfrom
dyc3/yaml-fmt-flow-scalars

Conversation

@dyc3

@dyc3 dyc3 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR formats flow scalar content in the yaml formatter.

implemented with fable 5

Test Plan

Docs

@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 81a7843

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

@dyc3 dyc3 changed the title dyc3/yaml fmt flow scalars feat(format/yaml): flow scalar content Jul 23, 2026
@github-actions github-actions Bot added A-Formatter Area: formatter L-Yaml Language: Yaml labels Jul 23, 2026
@dyc3
dyc3 marked this pull request as ready for review July 23, 2026 19:59

@ematipico ematipico left a comment

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.

This PR needs the same logic from its previous PR of the stack

Comment thread crates/biome_yaml_formatter/src/flow_scalar.rs Outdated
Comment thread crates/biome_yaml_formatter/src/flow_scalar.rs Outdated
@dyc3
dyc3 force-pushed the dyc3/yaml-fmt-flow-scalars branch from fd40954 to a360920 Compare July 24, 2026 13:14
Base automatically changed from dyc3/yaml-fmt-block-scalars to main July 24, 2026 20:45
dyc3 and others added 2 commits July 24, 2026 16:53
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01472YxeN6U2t4LWfaqkieAv
@dyc3
dyc3 force-pushed the dyc3/yaml-fmt-flow-scalars branch from a360920 to 81a7843 Compare July 25, 2026 15:38
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds shared YAML line iteration and a FormatFlowScalar formatter for single- and multiline plain, single-quoted, and double-quoted scalars. Multiline output normalises line breaks and continuation indentation while preserving blank-line runs. Scalar formatters now use the shared implementation, implicit map entries indent flow-scalar continuations, and new fixtures and tests cover multiline and carriage-return cases.

Possibly related PRs

Suggested reviewers: ematipico

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarises the YAML flow scalar formatting work.
Description check ✅ Passed The description is related to the change set and states the formatter now handles flow scalar content.
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-scalars

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: 1

🤖 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/tests/line_endings.rs`:
- Around line 37-40: Extend the flow-scalar line-ending coverage in
flow_scalar_with_carriage_return_line_breaks with a CRLF input case containing
\r\n, ensuring the expected formatted output uses normalized \n line breaks and
preserves indentation. Keep the existing lone-CR regression case and target the
ContentLines CRLF handling branch.
🪄 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: d979ff0e-c862-4532-af29-86aa34e92803

📥 Commits

Reviewing files that changed from the base of the PR and between 2c36626 and 81a7843.

⛔ Files ignored due to path filters (21)
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/plain/multiline.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/quote/multiline.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/construct-binary.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/multiline-plain-scalar-with-empty-line.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/multiline-scalar-at-top-level.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/multiline-scalar-in-mapping.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/plain-scalar-looking-like-key-comment-anchor-and-tag.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/sequence-entry-that-looks-like-two-with-wrong-indentation.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-2-27-invoice.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-6-4-line-prefixes.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-6-5-empty-lines.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-6-8-flow-folding.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-7-12-plain-lines.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-7-14-flow-sequence-entries.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-7-20-single-pair-explicit-entry.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-7-5-double-quoted-line-breaks.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-7-6-double-quoted-lines.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-7-9-single-quoted-lines.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-9-4-explicit-documents.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/various-trailing-comments.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/yaml/scalar/multiline.yaml.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (10)
  • crates/biome_yaml_formatter/src/content_lines.rs
  • crates/biome_yaml_formatter/src/flow_scalar.rs
  • crates/biome_yaml_formatter/src/lib.rs
  • crates/biome_yaml_formatter/src/yaml/auxiliary/block_content.rs
  • crates/biome_yaml_formatter/src/yaml/auxiliary/block_map_implicit_entry.rs
  • crates/biome_yaml_formatter/src/yaml/auxiliary/double_quoted_scalar.rs
  • crates/biome_yaml_formatter/src/yaml/auxiliary/plain_scalar.rs
  • crates/biome_yaml_formatter/src/yaml/auxiliary/single_quoted_scalar.rs
  • crates/biome_yaml_formatter/tests/line_endings.rs
  • crates/biome_yaml_formatter/tests/specs/yaml/scalar/multiline.yaml

Comment on lines +37 to +40
#[test]
fn flow_scalar_with_carriage_return_line_breaks() {
assert_format("a: \"foo\r\r bar\"\r", "a: \"foo\n\n bar\"\n");
}

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 | 🟡 Minor | ⚡ Quick win

Add a CRLF regression case.

\r\r only exercises lone-CR handling; it misses the dedicated \r\n branch in ContentLines.

Proposed test
 fn flow_scalar_with_carriage_return_line_breaks() {
     assert_format("a: \"foo\r\r bar\"\r", "a: \"foo\n\n  bar\"\n");
+    assert_format("a: \"foo\r\n bar\"\r\n", "a: \"foo\n  bar\"\n");
 }

As per coding guidelines, “All code changes must include appropriate tests”.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[test]
fn flow_scalar_with_carriage_return_line_breaks() {
assert_format("a: \"foo\r\r bar\"\r", "a: \"foo\n\n bar\"\n");
}
#[test]
fn flow_scalar_with_carriage_return_line_breaks() {
assert_format("a: \"foo\r\r bar\"\r", "a: \"foo\n\n bar\"\n");
assert_format("a: \"foo\r\n bar\"\r\n", "a: \"foo\n bar\"\n");
}
🤖 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/tests/line_endings.rs` around lines 37 - 40,
Extend the flow-scalar line-ending coverage in
flow_scalar_with_carriage_return_line_breaks with a CRLF input case containing
\r\n, ensuring the expected formatted output uses normalized \n line breaks and
preserves indentation. Keep the existing lone-CR regression case and target the
ContentLines CRLF handling branch.

Source: Coding guidelines

@dyc3
dyc3 merged commit 52283b6 into main Jul 26, 2026
27 checks passed
@dyc3
dyc3 deleted the dyc3/yaml-fmt-flow-scalars branch July 26, 2026 16:12
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