Skip to content

fix(format/yaml): move overflowing multiline flow scalars below their key - #11140

Open
dyc3 wants to merge 1 commit into
mainfrom
dyc3/yaml-fmt-multiline-scalar-break
Open

fix(format/yaml): move overflowing multiline flow scalars below their key#11140
dyc3 wants to merge 1 commit into
mainfrom
dyc3/yaml-fmt-multiline-scalar-break

Conversation

@dyc3

@dyc3 dyc3 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Before, a value always started after the key:

  description: A long first line that exceeds the configured width
    followed by another line

The fix gives multiline scalars two layouts:

  description: A short first line
    followed by another line

or, when the first line would overflow:

  description:
    A long first line that exceeds the configured width
    followed by another line

Found this while manually stress testing with some huge yaml files.

implemented by fable 5/opus 5

Test Plan

added tests

Docs

@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 30cac32

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 30, 2026
@dyc3
dyc3 marked this pull request as ready for review July 31, 2026 11:58
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The YAML formatter now detects line breaks in flow scalars and checks available width before placing them. Multiline scalars remain beside the key when they fit; otherwise, they move to an indented line. Single-line scalars keep their existing placement. New fixtures cover quoted, anchored, nested, and exact-width cases.

Possibly related PRs

  • biomejs/biome#10989: Changes related YAML mapping-value placement and fitting logic in the same formatter module.
  • biomejs/biome#11050: Extends related flow-scalar placement logic in block_map_implicit_entry.rs.
  • biomejs/biome#11057: Changes YAML property attachment and lookahead for related multiline scalar cases.

Suggested reviewers: siketyan, ematipico

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes moving overflowing multiline YAML flow scalars below their key.
Description check ✅ Passed The description explains the YAML formatting change and identifies the added test coverage.
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-multiline-scalar-break

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/specs/yaml/scalar/multiline_overflow.yaml`:
- Around line 13-15: Update the exact_fit fixture’s scalar text so the complete
line is exactly 80 characters wide, preserving its purpose of exercising the
equal-to-width formatting branch. Keep the existing YAML structure and add or
adjust only the necessary text; retain appropriate coverage for this exact-width
case.
🪄 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: 40286dd6-ce50-4259-9004-c868bb744384

📥 Commits

Reviewing files that changed from the base of the PR and between f399d3a and 30cac32.

⛔ Files ignored due to path filters (1)
  • crates/biome_yaml_formatter/tests/specs/yaml/scalar/multiline_overflow.yaml.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (2)
  • crates/biome_yaml_formatter/src/yaml/auxiliary/block_map_implicit_entry.rs
  • crates/biome_yaml_formatter/tests/specs/yaml/scalar/multiline_overflow.yaml

Comment on lines +13 to +15
exact_fit:
deeply:
- name: first line is exactly eighty columns wide, so the scalar stays put

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

Make the exact-width fixture exactly 80 columns.

Line 15 is 78 characters long. It does not test the equal-to-width branch.

Proposed fix
-    - name: first line is exactly eighty columns wide, so the scalar stays put
+    - name: first line is precisely eighty columns wide, so the scalar stays put

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
exact_fit:
deeply:
- name: first line is exactly eighty columns wide, so the scalar stays put
exact_fit:
deeply:
- name: first line is precisely eighty columns wide, so the scalar stays put
🤖 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/specs/yaml/scalar/multiline_overflow.yaml`
around lines 13 - 15, Update the exact_fit fixture’s scalar text so the complete
line is exactly 80 characters wide, preserving its purpose of exercising the
equal-to-width formatting branch. Keep the existing YAML structure and add or
adjust only the necessary text; retain appropriate coverage for this exact-width
case.

Source: Coding guidelines

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.

1 participant