Repository navigation
SA1009: Allow multiline tuple parenthesis layout - #4358
Merged
Merged
Conversation
Permit an indented closing parenthesis when a tuple expression's opening parenthesis is on its own line, and document the exception. Add boundary cases and the reported switch expression. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The exception also permits closing-line expression continuations, exceeding the documented restriction.
1 open issue
What changed in this PR
Addresses #3835 by allowing multiline tuple layouts in SA1009, including tuples in switch expressions.
Changes:
- Adds a tuple-specific spacing exception.
- Adds regression and near-miss tests.
- Updates rule documentation in all four locales.
| File | Description |
|---|---|
| test/StyleCop.Analyzers.Test.CSharp9/SpacingRules/SA1009CSharp9UnitTests.cs | Adds the reported switch-expression regression. |
| test/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1009CSharp7UnitTests.cs | Tests allowed tuple layouts and opening-parenthesis near misses. |
| src/StyleCop.Analyzers/SpacingRules/SA1009ClosingParenthesisMustBeSpacedCorrectly.cs | Adds the tuple spacing exception and updates its documentation. |
| documentation/zh-cn/SA1009.md | Documents the exception in Chinese. |
| documentation/SA1009.md | Documents the exception in English. |
| documentation/ru-ru/SA1009.md | Documents the exception in Russian. |
| documentation/cs-cz/SA1009.md | Documents the exception in Czech. |
Review effort: Balanced
Only allow an indented closing tuple parenthesis before statement or switch-arm delimiters. Keep reporting spacing violations before member-access continuations. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Allow an indented tuple closing parenthesis when the parenthesis itself ends its line, or a following comma or semicolon also ends the line. Cover final switch arms and same-line continuation cases. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4358 +/- ##
==========================================
- Coverage 97.62% 97.62% -0.01%
==========================================
Files 1336 1338 +2
Lines 149792 150250 +458
Branches 5098 5125 +27
==========================================
+ Hits 146239 146676 +437
- Misses 2265 2272 +7
- Partials 1288 1302 +14 🚀 New features to boost your workflow:
|
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
This was referenced Nov 13, 2026
Open
Open
Open
Merged
Open
Bump StyleCop.Analyzers from 1.2.0-beta.556 to 1.3.180
microsoftgraph/msgraph-sample-aspnet-core#256
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 #3835
SA1009 reports an indented closing parenthesis in a multiline tuple expression even when the opening parenthesis is alone on its line. This makes the reported switch expression layout trigger a false positive.
Allow the exception only when both tuple parentheses are each on their own line. Add the reported switch expression and near-miss cases, and update the SA1009 documentation in all existing locales. The regression test reproduced the SA1009 diagnostic before the analyzer change.
Validation: full SA1009 suites passed on C# 6 (72 tests), C# 9 (97 tests), and C# 15 (105 tests). The one-off probe with all standard and SX analyzers reported no compiler errors or analyzer exceptions for the exact snippet. The snippet does produce unrelated documentation, filename, file-header, and encoding diagnostics in the standalone probe.
Performance: no extra tree walk, allocations, or semantic analysis. The exception is checked only for closing parentheses that start a line; for tuple expressions it checks whether the opening parenthesis is alone on its line.
Behavior change: tuple expressions may have the closing parenthesis indented on its own line when the opening parenthesis is also on its own line.