Skip to content

Only indent a comparison's operand by its tier when the comparison breaks - #186

Merged
Rigidity merged 2 commits into
mainfrom
t3/flat-comparison-indent
Oct 24, 2026
Merged

Rigidity merged 2 commits into
mainfrom
t3/flat-comparison-indent

Conversation

@Rigidity

@Rigidity Rigidity commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Binary operators get one indentation level per precedence tier. Comparisons are fills that stay on the line when they fit, but their tier was still counted, so the operators in their right operand ended up two levels deep with no visible reason:

assert string.value == "tab"
        + byte(9)
        + "here";

Now the operators in a comparison's right operand are nested inside its fill. When the comparison stays flat they drop its tier, and when it breaks the tree-shaped layout is unchanged:

assert string.value == "tab"
    + byte(9)
    + "here";

assert long_value_name
    == first_value
        + second_value;

Higher precedence tiers inside the operand still nest (+ then *), and comparisons nested under a broken &&/|| chain follow the same rule. The JSON example is reformatted; no other .rue files in the repo change.


Note

Medium Risk
Changes core binary-expression emission logic in the formatter; behavior is well-covered by new tests but output diffs may affect any formatted Rue source.

Overview
Reworks binary-expression layout so comparison operators (==, !=, <, etc.) only add an indentation tier to their right operand when the comparison actually breaks across lines.

binary_span no longer emits each operator segment inline; it builds BinarySegment records and passes them through a new recursive binary_segments helper that nests the RHS inside Doc::fill_choice flat/broken layouts. When a comparison stays on one line, nested operators in the RHS drop that comparison’s tier (fixing extra indent after ==). When it breaks—or when a higher-precedence chain on the left already broke—the broken layout and tier stacking stay as before. shift_levels adjusts indent relative to an emission reference.

Doc::fill is now test-only (#[cfg(test)]); runtime formatting uses fill_choice from the new path. Adds formatter regression tests for flat/broken comparisons, logical chains, and nested precedence; examples/json.rue is reformatted to match.

Reviewed by Cursor Bugbot for commit 1c5fedf. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c24e787. Configure here.

Comment thread crates/rue-formatter/src/emit.rs
@Rigidity
Rigidity merged commit 580bb3e into main Oct 24, 2026
3 checks passed
@Rigidity
Rigidity deleted the t3/flat-comparison-indent branch October 24, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant