You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SA1143 currently rejects readable expanded conditional expressions when the condition spans multiple lines. Allow multiline conditions in the expanded layout, requiring the ? and : lines to align and be indented beyond the condition's final line. The expanded code fix continues to produce a valid layout by flattening the condition onto one line.
Added regression coverage for the reported layout, the expanded fix, and the existing analyzer tests' invalid indentation case. The regression test fails on master with SA1143 at the ? token. Updated the English and localized SA1143 documentation.
The analyzer's registration is unchanged; the existing conditional-expression callback now uses the condition's last token to determine its indentation. No additional callbacks or work for files without conditional expressions.
Allowing multiline conditions also lets nested false branches bypass the enclosing branch's continuation-indentation check. For example, this layout is now accepted:
right is aligned with the outer :, violating the continuation rule documented in documentation/SA1143.md:41–42. IsExpanded advances to next without checking its condition against the outer operator column, and the nested expression's callback is skipped. Validate the nested condition's continuation indentation before advancing, and require its operators to remain deeper than the enclosing operators. Add a regression test for this layout and a correctly indented counterpart.
Allowing multi-line conditions seems fine. It allows for some very unreadable code if misused, but forbidding it seem overly strict. Thumbs up on that one.
The other part about comparing indentation to the condition's last line is something that hasn't clicked for me yet. I would need to dig into that more, and I don't think I will manage that this week.
AArnott
deleted the
aarnott-issue-4367-sa1143-conditional-expressions-must-be-f-5ea37a
branch
October 21, 2026 21:47
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
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.
Fixes: #4367
SA1143 currently rejects readable expanded conditional expressions when the condition spans multiple lines. Allow multiline conditions in the expanded layout, requiring the ? and : lines to align and be indented beyond the condition's final line. The expanded code fix continues to produce a valid layout by flattening the condition onto one line.
Added regression coverage for the reported layout, the expanded fix, and the existing analyzer tests' invalid indentation case. The regression test fails on master with SA1143 at the ? token. Updated the English and localized SA1143 documentation.
The analyzer's registration is unchanged; the existing conditional-expression callback now uses the condition's last token to determine its indentation. No additional callbacks or work for files without conditional expressions.