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
{{ message }}
Repository navigation
SA1143: Preserve multiline branches when aligning closing delimiters - #4392
SA1143's existing layout fixes flatten multiline branch expressions. In the #4390 repro, aligning the collection expression's closing bracket with its opening bracket resolves the warning without collapsing the collection.
Add a separate closing-delimiter alignment action for collection expressions, object and collection initializers, tuples, and parenthesized expressions. Existing single-line, expanded, and aligned-chain actions remain unchanged.
Edit only leading whitespace before underindented closing delimiters, matching syntax-paired opening delimiters and respecting configured tab widths and indentation style. Preserve comments, blank lines, line breaks, literal contents, and unrelated formatting.
Offer the action only when a meaningful edit makes the complete conditional expression, including nested conditionals, satisfy SA1143. Leave directives and unsupported layouts for manual correction; avoid rewriting interpolation contents.
Update all existing documentation editions, including translating the previously English Czech page.
Validation
The exact issue repro was added first and failed against unchanged master product code because the alignment action was missing. Regression coverage includes nested collections, initializers, tuples, parentheses, comments, multiline/raw/interpolated literals, LF/CRLF, tabs, Fix All, existing actions, and cases where alignment must not be offered.
All 754 SA1143 tests passed across the C# 6 through C# 15 test projects on net10.0. The C# 15 project and all inherited projects built using SDK 10.0.403 with --no-incremental -maxcpucount:1 -warnaserror, with zero warnings or errors. git diff --check passed, and the resource accessor was regenerated by the build.
Scope and performance
Analyzer behavior and registrations are unchanged; its existing multiline-layout predicate is shared with the provider. Syntax traversal and candidate reparsing occur only in the code fix. This is intentionally a delimiter-only correction, not a general branch reformatter. The new action title uses neutral-English resource fallback for cultures without a translation.
Offer a separate syntax-aware alignment action only when whitespace-only edits resolve the conditional layout. Preserve existing actions and cover the issue 4390 repro, trivia, literals, tabs, and applicability boundaries.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The code fix can throw during registration for conditionals in unnamed invocation arguments or collection-expression elements and miss safely fixable nested-conditional alignment changes.
Adds an SA1143 code fix for #4390 that aligns closing delimiters without flattening multiline conditional branches, while preserving existing layout actions and analyzer behavior.
Changes:
Adds delimiter-only alignment with whitespace preservation and validation of the resulting conditional layout.
Adds regression coverage for supported syntax, formatting preservation, Fix All, and inapplicable cases.
Updates all four documentation editions and adds the action’s resource string.
Select the innermost matching conditional when syntax wrappers share its span, and align nested branches against their own operators without duplicating delimiter edits. Add regressions for invocation arguments, collection elements, and nested branches.
Translate the new action title into Russian and Simplified Chinese to satisfy existing resource completeness checks.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
❌ Patch coverage is 99.39024% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.64%. Comparing base (a29da78) to head (c14103b). ⚠️ Report is 1 commits behind head on master.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The code fix can leave adjacent multiline parenthesized operands misaligned because it calculates closing-delimiter positions without accounting for preceding indentation edits on the opening delimiter’s line.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Account for prior indentation edits when aligning delimiters
When two multiline parenthesized operands meet on a ) + ( line, aligning the first ) also shifts the second (, but this calculation still uses its original column. For example, the second opening delimiter moves from column 16 to 18 while its closing delimiter is placed at column 16; SA1143 accepts the result even though the pair remains misaligned. Account for preceding indentation edits on each opening delimiter's line when computing target columns, and add a regression for this layout.
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.
SA1143's existing layout fixes flatten multiline branch expressions. In the #4390 repro, aligning the collection expression's closing bracket with its opening bracket resolves the warning without collapsing the collection.
Fixes #4390
Approach
Validation
The exact issue repro was added first and failed against unchanged master product code because the alignment action was missing. Regression coverage includes nested collections, initializers, tuples, parentheses, comments, multiline/raw/interpolated literals, LF/CRLF, tabs, Fix All, existing actions, and cases where alignment must not be offered.
All 754 SA1143 tests passed across the C# 6 through C# 15 test projects on net10.0. The C# 15 project and all inherited projects built using SDK 10.0.403 with
--no-incremental -maxcpucount:1 -warnaserror, with zero warnings or errors.git diff --checkpassed, and the resource accessor was regenerated by the build.Scope and performance
Analyzer behavior and registrations are unchanged; its existing multiline-layout predicate is shared with the provider. Syntax traversal and candidate reparsing occur only in the code fix. This is intentionally a delimiter-only correction, not a general branch reformatter. The new action title uses neutral-English resource fallback for cultures without a translation.