Skip to content

SA1009: Allow multiline tuple parenthesis layout - #4358

Merged
AArnott merged 3 commits into
masterfrom
aarnott-cuddly-guacamole
Oct 20, 2026
Merged

AArnott merged 3 commits into
masterfrom
aarnott-cuddly-guacamole

Conversation

@AArnott

@AArnott AArnott commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

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.

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>
@AArnott
AArnott marked this pull request as ready for review October 20, 2026 00:50
Copilot AI balanced review requested due to automatic review settings October 20, 2026 00:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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>
Copilot AI balanced review requested due to automatic review settings October 20, 2026 00:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The closing-line condition still rejects valid standalone parentheses and permits some lines containing additional code.

1 open issue
1 resolved since last review

Review effort: Balanced

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>
Copilot AI balanced review requested due to automatic review settings October 20, 2026 01:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

No blocking findings remain, but full CI validation is unconfirmed and requires human verification before approval.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.62%. Comparing base (2b8bc7d) to head (b226ed2).
⚠️ Report is 5 commits behind head on master.

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AArnott
AArnott merged commit 8b89084 into master Oct 20, 2026
30 checks passed
@AArnott
AArnott deleted the aarnott-cuddly-guacamole branch October 20, 2026 01:24
This was referenced Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SA1009 - Behavior in Switch expression

2 participants