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
SA1137 currently rejects a common layout where a collection expression's closing bracket is vertically aligned with an opening bracket that follows code on the same line. Its standard fix also cannot preserve that preferred alignment.
The analyzer now accepts either the opening bracket line's indentation or the opening bracket's visual column. Both SA1137 and SA1500 offer an alternate fix to align the closing bracket with the opening bracket, while retaining their existing fixes. Alignment honors configured tab size and tab usage; SA1500 Fix All also tracks an opening bracket moved earlier in the same batch. Rule documentation and localized action text are updated.
The regression test failed on the pre-change code with SA1137 at the closing bracket. New tests cover accepted and rejected tab alignment, tab-aware fixes, and nested SA1500 Fix All. SA1137 and SA1500 suites pass on C# 12 and C# 15, and SA1137 plus resource localization tests pass on C# 6. The full solution Debug build succeeds with zero warnings. Relevant documentation and localization checks pass; the full documentation test run requires prebuilt DocFX output that was not present locally.
Performance impact: SA1137 remains limited to collection-expression nodes. Tab-aware column checks run only for inline opening brackets with closing brackets on another line; there is no syntax-tree walk or semantic analysis. Column generation in code fixes runs only when a fix is requested.
Allow collection-expression closing brackets to align with an inline opening bracket and offer that alignment as an alternate fix for SA1137 and SA1500.
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
Incorrect tab-column handling causes false or missed alignment diagnostics and faulty fixes, while alternate Fix All can misalign nested collection brackets and introduce new violations.
This PR addresses #4399 by allowing collection-expression closing brackets to align with inline opening brackets, extending SA1137 and the related code fixes.
Changes:
Accepts either line indentation or opening-bracket alignment in SA1137.
Adds alternate alignment actions to SA1137 and SA1500, with regression tests.
Updates rule documentation and localized action text.
❌ Patch coverage is 94.18605% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.64%. Comparing base (37d8d30) to head (32b0c2a). ⚠️ Report is 3 commits behind head on master.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Alternate Fix All still introduces SA1137 by misaligning an inner closing bracket after moving preceding code, requiring corrected column calculations and regression tests.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Fix SA1137 alignment after alternate Fix All moves code
Alternate Fix All still introduces SA1137 when it moves code before an inline opening bracket without replacing that bracket. For int[][] values = [(int[])[ followed by 1, 2]];, moving the cast leaves this fallback aligning the inner ] at column 29 instead of 15. Calculate the opening bracket's column after pending replacements to preceding tokens, and add regressions for wrapped collections and moved return statements.
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 #4399
SA1137 currently rejects a common layout where a collection expression's closing bracket is vertically aligned with an opening bracket that follows code on the same line. Its standard fix also cannot preserve that preferred alignment.
The analyzer now accepts either the opening bracket line's indentation or the opening bracket's visual column. Both SA1137 and SA1500 offer an alternate fix to align the closing bracket with the opening bracket, while retaining their existing fixes. Alignment honors configured tab size and tab usage; SA1500 Fix All also tracks an opening bracket moved earlier in the same batch. Rule documentation and localized action text are updated.
The regression test failed on the pre-change code with SA1137 at the closing bracket. New tests cover accepted and rejected tab alignment, tab-aware fixes, and nested SA1500 Fix All. SA1137 and SA1500 suites pass on C# 12 and C# 15, and SA1137 plus resource localization tests pass on C# 6. The full solution Debug build succeeds with zero warnings. Relevant documentation and localization checks pass; the full documentation test run requires prebuilt DocFX output that was not present locally.
Performance impact: SA1137 remains limited to collection-expression nodes. Tab-aware column checks run only for inline opening brackets with closing brackets on another line; there is no syntax-tree walk or semantic analysis. Column generation in code fixes runs only when a fix is requested.