Repository navigation
SA1137: align malformed array initializer brackets - #4272
Merged
Merged
Conversation
Use the containing expression to align unindented array initializer braces and elements, preserving trivia and configured indentation. Cover the reported layout, Fix All, comments, tabs, and line endings. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4272 +/- ##
========================================
Coverage 97.61% 97.61%
========================================
Files 1285 1285
Lines 137307 137442 +135
Branches 4451 4456 +5
========================================
+ Hits 134029 134167 +138
+ Misses 2113 2111 -2
+ Partials 1165 1164 -1 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Fix All can discard nested SA1137 corrections contained within an initializer-wide edit.
1 open finding
What changed in this PR
Fixes SA1137 array-initializer indentation by anchoring malformed initializers to their containing expression.
Changes:
- Reworks array-initializer indentation and overlapping Fix All handling.
- Adds regression coverage for layouts, settings, trivia, and line endings.
- Updates English, Czech, and Russian documentation.
| File | Description |
|---|---|
test/StyleCop.Analyzers.Test/ReadabilityRules/SA1137UnitTests.cs |
Adds regression and configuration coverage. |
src/StyleCop.Analyzers.CodeFixes/ReadabilityRules/IndentationCodeFixProvider.cs |
Implements initializer-wide alignment and overlap handling. |
documentation/SA1137.md |
Documents the new behavior. |
documentation/ru-ru/SA1137.md |
Updates Russian documentation. |
documentation/cs-cz/SA1137.md |
Updates Czech documentation. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+177
to
+180
| if (!changes.Exists(change => change.Span.Contains(textChange.Span))) | ||
| { | ||
| changes.RemoveAll(change => textChange.Span.Contains(change.Span)); | ||
| changes.Add(textChange); |
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
Open
This was referenced Nov 29, 2026
Open
Open
Open
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 #2854
The SA1137 code fix used an unindented opening array-initializer brace as its anchor, moving the closing brace to column 1 while leaving the initializer elements over-indented. For this malformed layout, the fix now aligns both braces with the containing expression and places the elements one configured indentation level deeper. Only indentation whitespace is changed; comments, blank lines, shared-line elements, and line endings are preserved. Fix All handles overlapping element and brace corrections.
Added the reporter's exact layout to
SA1137UnitTestsbefore changing product code. The regression test fails on master (5fb0ffaf999434bf5b78b7c8bb86c8334ac46b37): its fixed-output diff shows both braces at column 1 instead of the expected expression indentation. Additional tests cover implicit/explicit arrays, declaration initializers, comments, tabs, two-space indentation, LF/CRLF, and the unchanged zero-indentation-expression behavior. Updated the English, Czech, and Russian rule documentation.Validation (SDK 10.0.401):
dotnet build -c Release -maxcpucount:1: succeeded, zero warnings/errors.net10.0andnet472.net10.0.Performance: the analyzer is unchanged, so analyzer performance and diagnostic reporting are unchanged. The additional syntax and whitespace work runs only in the code fix; indentation settings are read through the existing settings helper. The behavior change is limited to malformed array initializers with an unindented opening brace and mismatched braces on separate lines.
Draft for CI and human review; no merge or issue comment/closure performed.