Skip to content

SA1654: encode generic brackets in cref - #4328

Merged
AArnott merged 4 commits into
masterfrom
aarnott-sa1654-properly-encode-generic-brackets
Oct 17, 2026
Merged

AArnott merged 4 commits into
masterfrom
aarnott-sa1654-properly-encode-generic-brackets

Conversation

@AArnott

@AArnott AArnott commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Adds SA1654 to enforce brace syntax for generic type arguments in XML documentation cref attributes, and provides a code fix that replaces escaped brackets while preserving the rest of the reference. SA1653 remains unchanged; the new rule uses SA1654 because that ID is already occupied.

The issue-shaped test reproduces the reported DisposalScope<T> example and fails on the prior implementation with zero diagnostics instead of one. Tests also cover brace syntax, encoded text outside cref, and nested generic arguments. The analyzer registers only for XML cref attributes; the code fix runs only when requested and does not add analyzer work beyond those callbacks.

Validation: SA1654 tests pass on the C# 6 and C# 15 test projects; the code-fix project builds with zero warnings.

Fixes #758

Add an analyzer and code fix for using braces in generic cref attributes, with tests and documentation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@AArnott
AArnott marked this pull request as ready for review October 17, 2026 02:39
Copilot AI balanced review requested due to automatic review settings October 17, 2026 02:39

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 fix can corrupt operator references, and detection misses mixed delimiters and numeric XML escapes.

2 open issues
1 file not reviewed
  • src/StyleCop.Analyzers/Lightup/.generated/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.CSharpResxGenerator/DocumentationResources.Designer.cs: Generated file
What changed in this PR

Adds SA1654 to prefer braces for generic arguments in XML documentation references, addressing #758 without changing SA1653.

Changes:

  • Adds the analyzer and code fix, including Fix All support.
  • Adds regression tests and diagnostic resources.
  • Documents the rule in English, Czech, Russian, and Simplified Chinese.
File Description
test/​StyleCop.Analyzers.Test/​DocumentationRules/​SA1654UnitTests.cs Tests detection and fixes.
src/​StyleCop.Analyzers/​Lightup/​.generated/​Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/​Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.CSharpResxGenerator/​DocumentationResources.Designer.cs Adds generated resource accessors.
src/​StyleCop.Analyzers/​DocumentationRules/​SA1654ProperlyEncodeGenericBrackets.cs Implements SA1654 detection.
src/​StyleCop.Analyzers/​DocumentationRules/​DocumentationResources.resx Adds diagnostic and fix strings.
src/​StyleCop.Analyzers/​AnalyzerReleases.Unshipped.md Registers the new rule.
src/​StyleCop.Analyzers.CodeFixes/​DocumentationRules/​SA1654CodeFixProvider.cs Implements single-fix and Fix All.
documentation/​zh-cn/​toc.yml Adds Chinese navigation entry.
documentation/​zh-cn/​SA1654.md Documents the rule in Chinese.
documentation/​zh-cn/​DocumentationRules.md Adds Chinese rule listing.
documentation/​toc.yml Adds English navigation entry.
documentation/​SA1654.md Documents the rule in English.
documentation/​ru-ru/​toc.yml Adds Russian navigation entry.
documentation/​ru-ru/​SA1654.md Documents the rule in Russian.
documentation/​ru-ru/​DocumentationRules.md Adds Russian rule listing.
documentation/​DocumentationRules.md Adds English rule listing.
documentation/​cs-cz/​toc.yml Adds Czech navigation entry.
documentation/​cs-cz/​SA1654.md Documents the rule in Czech.
documentation/​cs-cz/​DocumentationRules.md Adds Czech rule listing.

Review effort: Balanced

Add Russian and Chinese resources for the new rule and use its repository-local documentation link until publication.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 17, 2026 02:46

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

The code fix can corrupt operator references by replacing operator symbols alongside generic delimiters.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Low severity Use file-scoped namespace in the new file

src/​StyleCop.Analyzers.CodeFixes/​DocumentationRules/​SA1654CodeFixProvider.cs:5

This new file uses a block-scoped namespace, but AGENTS.md requires file-scoped namespaces in new files. Convert the declaration and remove the outer braces, matching the new analyzer and test files.

1 file not reviewed
  • src/StyleCop.Analyzers/Lightup/.generated/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.CSharpResxGenerator/DocumentationResources.Designer.cs: Generated file

Review effort: Balanced

@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.50000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.67%. Comparing base (c1c052b) to head (e77733c).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4328      +/-   ##
==========================================
+ Coverage   97.66%   97.67%   +0.01%     
==========================================
  Files        1324     1328       +4     
  Lines      146324   146874     +550     
  Branches     4945     4961      +16     
==========================================
+ Hits       142904   143461     +557     
+ Misses       2171     2163       -8     
- Partials     1249     1250       +1     
🚀 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.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 17, 2026 02:58

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

Fix All repeatedly scans the entire document for each diagnostic, introducing avoidable quadratic traversal work.

1 open issue
2 resolved since last review
1 file not reviewed
  • src/StyleCop.Analyzers/Lightup/.generated/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.CSharpResxGenerator/DocumentationResources.Designer.cs: Generated file

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 17, 2026 03:06

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.

🟢 Approval recommended

No blocking issues remain, and targeted regression coverage addresses the reported behavior and prior feedback.

No open issues 🎉

1 resolved since last review
1 file not reviewed
  • src/StyleCop.Analyzers/Lightup/.generated/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.CSharpResxGenerator/DocumentationResources.Designer.cs: Generated file

Review effort: Balanced

This was referenced Nov 24, 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.

Implement SA1653 (ProperlyEncodeGenericBrackets)

2 participants