Repository navigation
Update SA1137 to check collection expressions - #4137
Merged
Merged
Conversation
From bjornhellander/NewStyleCopAnalyzers#23. Adapted while cherry-picking: added WorkItem(3904) to the tests. This replaces #3910. (cherry picked from commit cfdf2d45e392ff1090454f18ca93a34086faacd1)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4137 +/- ##
========================================
Coverage 97.39% 97.39%
========================================
Files 1073 1074 +1
Lines 122990 123103 +113
Branches 4173 4173
========================================
+ Hits 119781 119894 +113
Misses 2108 2108
Partials 1101 1101 🚀 New features to boost your workflow:
|
AArnott
marked this pull request as ready for review
October 8, 2026 04:01
This was referenced Oct 8, 2026
Closed
This was referenced Nov 11, 2026
Bump StyleCop.Analyzers from 1.2.0-beta.556 to 1.3.180
microsoftgraph/aspnetcore-webhooks-sample#436
Open
Closed
This was referenced Nov 23, 2026
Open
[DPDBT] Bump Microsoft.CodeAnalysis.Analyzers and 6 others
sergey-rybalkin/CommandLine.Generators#63
Open
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.
Fixes #3904. Part of #4044 (#4007 collection expressions).
This replaces #3910 with @bjornhellander's fix from bjornhellander/NewStyleCopAnalyzers#23 (cherry-picked with
-x, authorship kept). His review on #3910 suggested a different approach, and this is that approach.Behavior change: SA1137 now checks collection expressions (
[ ... ]) the same way it checks initializers. The elements must share one indentation, and the closing bracket of a multi-line collection expression must line up with its opening bracket when the opening bracket starts its own line. Before, code like the following wasn't reported:Commits:
cfdf2d45e: registersSyntaxKindEx.CollectionExpressionand checks the brackets and elements. Tests cover single-line expressions, an opening bracket on the previous line or the same line, and code fixes. I only addedWorkItem(3904)... other) and nested collection expressions passed as an argument, with the code fix.Tests: all SA1137 tests pass on C# 12–15 locally.