Repository navigation
SA1500/SA1513: Allow continuations after switch expression closing braces - #4334
Merged
Merged
Conversation
Preserve SA1500 multiline brace placement while allowing expression continuations. Exempt switch expression closing braces from SA1513 and preserve continuations in the SA1500 code fix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Multiline-string final arms can bypass SA1500, and nested-switch Fix All can leave a diagnostic unresolved.
2 open issues
What changed in this PR
Addresses #4332 by allowing switch-expression continuations under SA1500 and SA1513 while retaining multiline brace-layout requirements.
Changes:
- Exempt switch-expression continuations from newline and blank-line checks.
- Update the SA1500 code fix and add layout and spacing regression tests.
- Synchronize rule documentation across four languages.
| File | Description |
|---|---|
| test/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1013CSharp8UnitTests.cs | Tests closing-brace spacing and result access. |
| test/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1012CSharp8UnitTests.cs | Tests opening-brace spacing. |
| test/StyleCop.Analyzers.Test.CSharp8/LayoutRules/SA1513CSharp8UnitTests.cs | Tests continuations without blank lines. |
| test/StyleCop.Analyzers.Test.CSharp8/LayoutRules/SA1500CSharp8UnitTests.cs | Tests continuations, brace placement, and fixes. |
| src/StyleCop.Analyzers/LayoutRules/SA1513ClosingBraceMustBeFollowedByBlankLine.cs | Exempts switch-expression closing braces. |
| src/StyleCop.Analyzers/LayoutRules/SA1500BracesForMultiLineStatementsMustNotShareLine.cs | Allows same-line continuations. |
| src/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1500CodeFixProvider.cs | Preserves trailing continuations. |
| documentation/zh-cn/SA1513.md | Updates Chinese blank-line guidance. |
| documentation/zh-cn/SA1500.md | Updates Chinese brace-layout guidance. |
| documentation/SA1513.md | Documents the blank-line exemption. |
| documentation/SA1500.md | Clarifies switch-expression brace layout. |
| documentation/ru-ru/SA1513.md | Updates Russian blank-line guidance. |
| documentation/ru-ru/SA1500.md | Updates Russian brace-layout guidance. |
| documentation/cs-cz/SA1513.md | Updates Czech blank-line guidance. |
| documentation/cs-cz/SA1500.md | Updates Czech brace-layout guidance. |
Review effort: Balanced
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4334 +/- ##
========================================
Coverage 97.66% 97.67%
========================================
Files 1331 1331
Lines 147246 147515 +269
Branches 4977 4979 +2
========================================
+ Hits 143813 144080 +267
Misses 2176 2176
- Partials 1257 1259 +2 🚀 New features to boost your workflow:
|
Use the preceding token's end line and retain separators between closing braces processed by Fix All. Add regressions for both review findings. 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 21, 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.

Switch expressions can continue after their closing brace, but SA1500 and SA1513 currently require a new line or blank line before operators such as
??.Fixes #4332
Changes
This narrows the policy introduced by #4035 rather than exempting switch expressions from SA1500 entirely. Member and element access require parentheses around the switch expression in C#; regression coverage uses those valid forms.
Verification
The reported null-coalescing cases failed against the unchanged analyzers with SA1500/SA1513 diagnostics before the product changes. Added coverage for other operators, comments, whitespace and spacing fixes, single-line expressions, and closing braces sharing the final arm's line with and without a trailing comma.
Built the C# 15 test project and its inherited projects with SDK 10.0.402, with zero warnings or errors. The complete SA1500, SA1513, SA1012, and SA1013 suites pass under C# 6 and every compiler from C# 8 through C# 15.
Performance
No new callbacks, semantic-model queries, tree walks, or allocations. SA1500 adds a token/parent-kind guard within its existing brace callback; SA1513 adds a parent-kind check for closing braces and skips the remaining analysis for switch expressions.