Preserve breaking conditional statement#1222
Open
matthewnessworthy wants to merge 5 commits intocarthage-software:mainfrom
Open
Preserve breaking conditional statement#1222matthewnessworthy wants to merge 5 commits intocarthage-software:mainfrom
matthewnessworthy wants to merge 5 commits intocarthage-software:mainfrom
Conversation
azjezz
requested changes
Feb 26, 2026
Member
azjezz
left a comment
There was a problem hiding this comment.
LGTM. But before we can merge, please remove Claude from git history.
I don't mind using Claude, but it should never be in commit history for git blame :)
Author
|
@azjezz sure thing, I'll make the changes soon. |
2c3b0c2 to
de924db
Compare
Member
|
@matthewnessworthy you should use |
1422fe6 to
0c5198b
Compare
Author
|
@azjezz i ran |
Add a new bool field `preserve_breaking_condition_statement` to the `generate_formatter_settings!` macro in settings.rs, with `default_false`. This generates the field in both `FormatSettings` and `RawFormatSettings`. Set correct values in all 6 presets: - Default=false, PSR-12=false, Hack=false (no preservation) - Pint=true, Tempest=true, Drupal=true (preserve multi-line conditions) No behavioral change — the field is declared but not yet consumed.
When `preserve_breaking_condition_statement` is enabled and a condition was originally broken across multiple lines, force PER Coding Style 3.0 output: first condition on indented next line, closing paren on own line, and each boolean operator on its own line. Changes to print_condition() in misc.rs: - Compute `must_break` from setting + `has_new_line_in_range` detection - Guard expandable expression branch with `&& !must_break` - Replace soft line breaks with conditional hard/soft based on must_break - Add `.with_break(must_break)` to force group breaking - Thread `must_break_condition` flag through FormatterState Changes to binaryish.rs: - When `must_break_condition` is set, force hard line breaks before binary operators so each condition appears on its own line Automatically covers all 7 call sites (if, elseif, while, do-while, switch, match) without touching any call-site code.
Add enabled/disabled test fixture pairs: Enabled test covers all 6 control structures (if, elseif, while, do-while, switch, match) with multi-line conditions producing PER-style output where each boolean operator appears on its own line. Single-line conditions remain untouched. Disabled test confirms the formatter collapses multi-line conditions when the setting is off. Idempotency is verified automatically by the test_case! macro.
0c5198b to
e7c1a8f
Compare
Author
|
@azjezz rebased, formatted, and conflicts fixed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 What Does This PR Do?
Adds a new
preserve_breaking_condition_statementformatter setting that preserves multi-linecondition layouts in control structures (
if,elseif,while,do-while,switch,match)following PER Coding Style 3.0 rules.
🔍 Context & Motivation
The formatter already has
preserve_breaking_conditional_expressionfor ternary expressions, butthere's no equivalent for control structure conditions. When a developer intentionally breaks a
complex condition across multiple lines for readability, the formatter should respect that layout
when this setting is enabled — placing each boolean operator on its own line and the closing
parenthesis on its own line.
php-fig.org/per/coding-style#51-if-elseif-else
🛠️ Summary of Changes
preserve_breaking_condition_statementbool field toFormatSettingsandRawFormatSettingsvia thegenerate_formatter_settings!macro, defaulting tofalse.true; Default, PSR-12, Hack =false.must_breakdetection inprint_condition()usinghas_new_line_in_rangebetween the opening parenthesis and the condition.must_break_conditionflag toFormatterState, threaded through tobinaryish.rsto force hard line breaks before binary operators when inside a must-break condition.📂 Affected Areas
🔗 Related Issues or PRs
Related to #869
📝 Notes for Reviewers
When enabled, a multi-line condition like: