Repository navigation
SA1137: fix closing brace indentation when inline - #4216
Merged
Merged
Conversation
Insert a line break before inline closing braces and brackets while preserving comments and the document's line endings. Share the correction between individual fixes and Fix All without changing analyzer behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4216 +/- ##
========================================
Coverage 97.57% 97.57%
========================================
Files 1276 1276
Lines 135692 135819 +127
Branches 4383 4385 +2
========================================
+ Hits 132397 132529 +132
+ Misses 2135 2132 -3
+ Partials 1160 1158 -2 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Closing delimiters following leading comments still bypass the new fix path.
1 open finding
What changed in this PR
Fixes SA1137’s code fix so inline closing delimiters move to the correctly indented next line.
Changes:
- Shares newline-aware text-change logic between individual and Fix All operations.
- Preserves preceding comments and source line endings.
- Adds brace and C# 12 collection-expression regression tests.
| File | Description |
|---|---|
SA1137UnitTests.cs |
Tests inline initializer braces, trivia, comments, and line endings. |
SA1137CSharp12UnitTests.cs |
Tests inline collection-expression brackets. |
IndentationCodeFixProvider.cs |
Inserts a matching line ending before inline closing delimiters. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Use the whitespace-only line-start check so comments preceding a closing delimiter do not bypass newline insertion. Add LF and CRLF regression coverage for braces and brackets. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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 20, 2026
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 #3296
The SA1137 code fix previously inserted indentation before an inline closing brace without moving the brace to its own line. It now replaces only the whitespace immediately before an inline closing brace or bracket with a matching line ending and the expected indentation. Comments are preserved, and individual fixes and Fix All use the same text-change logic. Analyzer diagnostics and valid formatting behavior are unchanged.
Regression evidence: before changing product code, five
VerifyCSharpFixAsynccases failed on master (0931d709f59f428a084728c38ec4b27f670d1076) at Iterative code fix application, showing42 };instead of42followed by a newline and};. The extra spaces accumulate because the diagnostic remains after the broken fix. The C#6 reproduction declaresint[] _;to retain the reporter's_ = new[]assignment while compiling on the oldest supported compiler.Coverage includes no preceding whitespace, spaces, a tab, block comments, LF/CRLF, and the shared C#12 collection-expression closing-bracket path. The verifier checks individual fixes and Fix All. Existing tests cover correctly positioned braces, single-line initializers, and ordinary indentation corrections.
Validation with SDK 10.0.401 (allowed by global.json):
net6.0andnet472.net6.0: all pass (6 cases per project through C#11, 8 cases per project from C#12).Performance: code-fix-only change; no analyzer changes, registrations, semantic-model work, or analyzer runtime cost. The fix reuses the document text and the existing line-ending helper.
Inspected the closed, unmerged #3544 for prior intent; this is a narrower implementation in the code fix rather than its analyzer-side behavior change. Documentation remains unchanged because rule behavior is unchanged.
This PR remains a draft pending CI; humans review and merge.