Repository navigation
SA1017: Require spacing after parameter attributes - #4321
Conversation
Report missing whitespace after the last attribute list on parameters and type parameters, using the existing token spacing code fix. Preserve comments, line breaks, and adjacent attribute lists. Fixes #3118 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The new diagnostic incorrectly instructs users to remove preceding whitespace instead of adding following whitespace.
1 open finding
What changed in this PR
Extends SA1017 to require spacing after parameter and type-parameter attributes, addressing #3118.
Changes:
- Detects missing following whitespace using the existing token-spacing fix.
- Adds regression coverage for declaration forms, comments, and line breaks.
- Updates rule documentation in four languages.
| File | Description |
|---|---|
| test/StyleCop.Analyzers.Test/SpacingRules/SA1017UnitTests.cs | Adds spacing and code-fix regression cases. |
| test/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1017CSharp8UnitTests.cs | Covers the nullable out example. |
| src/StyleCop.Analyzers/SpacingRules/SA1017ClosingAttributeBracketsMustBeSpacedCorrectly.cs | Checks whitespace after parameter attributes. |
| documentation/zh-cn/SA1017.md | Updates Simplified Chinese guidance. |
| documentation/SA1017.md | Documents the expanded rule. |
| documentation/ru-ru/SA1017.md | Updates Russian guidance. |
| documentation/cs-cz/SA1017.md | Updates Czech guidance. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4321 +/- ##
==========================================
+ Coverage 97.62% 97.63% +0.01%
==========================================
Files 1319 1321 +2
Lines 144254 144864 +610
Branches 4864 4873 +9
==========================================
+ Hits 140825 141437 +612
Misses 2173 2173
+ Partials 1256 1254 -2 🚀 New features to boost your workflow:
|
Use a separate localized message for missing following whitespace while preserving the existing preceding-space message. Assert both messages in regression tests and regenerate resource accessors. The new message uses English fallback in other cultures. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The narrowly scoped change has focused regression coverage and no identified blocking issues.
0 open findings
1 resolved since last review
Files not reviewed (1)
- src/StyleCop.Analyzers/Lightup/.generated/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.CSharpResxGenerator/SpacingResources.Designer.cs: Generated file
🧠 Review effort: Balanced
Add Russian and Simplified Chinese translations for the new diagnostic so localized resource completeness checks pass without weakening coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation and regression coverage leave no unresolved blocking issues; tests were not rerun during this review.
0 open findings
Files not reviewed (1)
- src/StyleCop.Analyzers/Lightup/.generated/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.CSharpResxGenerator/SpacingResources.Designer.cs: Generated file
🧠 Review effort: Balanced

SA1017 checked whitespace before closing attribute brackets but missed missing whitespace after them, allowing declarations such as
[NotNullWhen(true)]out string? foo.Fixes #3118
Require whitespace after the last attribute list on a parameter or type parameter when the declaration continues on the same line. Reuse the existing token-spacing code fix, preserving comments, line breaks, and adjacent attribute lists. Multiple spaces remain the responsibility of SA1025. Update the English, Czech, Russian, and Simplified Chinese rule documentation.
Behavior change: SA1017 now reports missing spaces after parameter and type-parameter attributes. Other attribute targets are unchanged.
Verification: The reporter's exact nullable
outexample and additional parameter cases failed against unchanged master with the expected missing-diagnostic failures before the analyzer change. The build completes with zero warnings, and the complete SA1017 suite passes under every C# 6-15 test project on net10.0, plus the oldest and newest projects on net472. Regression coverage includes modifiers, constructors, delegates, indexers, type parameters, adjacent attributes, comments, multiline attributes, and fixes on both sides of a bracket.Performance: Adds syntax and trivia checks only for closing attribute brackets on parameters and type parameters, within the existing shared token walk. No new registrations, semantic-model calls, tree walks, or per-callback allocations; no benchmark was run.