Skip to content

SA1314: Rename type parameters in documentation crefs - #4361

Merged
AArnott merged 5 commits into
masterfrom
aarnott-improved-spoon
Oct 20, 2026
Merged

AArnott merged 5 commits into
masterfrom
aarnott-improved-spoon

Conversation

@AArnott

@AArnott AArnott commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #2966

The SA1314 rename fix updated code references but left generic type-parameter references in documentation cref attributes unchanged. The fix now updates matching references in documentation comments on the declaring type, including partial declarations, while preserving references shadowed by nested or generic method type parameters.

The regression test failed on the original implementation with the reported unchanged cref, and now passes. SA1314 tests pass in the C# 6 and C# 15 test projects. The extra work runs only when applying this code fix and scans documentation comments on the containing type's declarations; no analyzer-path performance impact.

Rename matching type-parameter references in same-type documentation crefs when applying the SA1314 code fix.

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

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

Generated partial declarations can cause crashes, and the scope filter skips valid documentation references.

3 open issues
What changed in this PR

Extends the SA1314 rename fix to update documentation cref references, addressing #2966.

Changes:

  • Updates matching crefs across containing-type declarations before renaming.
  • Adds regression tests for constructor documentation, shadowing, and partial types.
File Description
test/​StyleCop.Analyzers.Test/​NamingRules/​SA1314UnitTests.cs Adds cref rename regression tests.
src/​StyleCop.Analyzers.CodeFixes/​NamingRules/​SA1314CodeFixProvider.cs Adds scope-aware documentation scanning and updates.

Review effort: Balanced

Skip generated declarations, scope cref updates to unshadowed type parameters, and cover cross-document references.

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:47

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

Cref rewriting can alter unrelated placeholders and capture existing references, breaking valid documentation links.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Avoid rewriting placeholders from unrelated generic declarations

src/​StyleCop.Analyzers.CodeFixes/​NamingRules/​SA1314CodeFixProvider.cs:161

Name and ordinal also match independent placeholders declared by unrelated generic crefs. When fixing Foo<IDENT>, Other{IDENT,TIDENT}.M(IDENT) becomes Other{TIDENT,TIDENT}.M(TIDENT). If Other<TFirst,TSecond> overloads M(TFirst) and M(TSecond), this collapses distinct placeholders and can make the reference ambiguous. The same filter rewrites unrelated generic-method crefs such as M{IDENT,TIDENT}(IDENT,TIDENT). Resolve the generic declaration represented by each cref before selecting its placeholders, rather than matching only name and ordinal. Add regressions for unrelated generic types and methods with these name collisions.

Medium severity Prevent cref placeholder replacement from capturing source type parameters

src/​StyleCop.Analyzers.CodeFixes/​NamingRules/​SA1314CodeFixProvider.cs:200

This replacement also changes ordinary references bound to the source type parameter before RenameHelper invokes Roslyn's renamer. For Foo<IDENT> with M<T>(IDENT x, T y), a valid cref="M{TIDENT}(IDENT,TIDENT)" becomes M{TIDENT}(TIDENT,TIDENT). The first argument now binds to the cref-local method parameter instead of the enclosing type parameter, so the cref no longer matches M. The later semantic rename sees that already-changed binding. Leave ordinary source-symbol references to the semantic renamer and make the additional placeholder repairs collision-safe. Add a regression for this capture case.

3 resolved since last review

Review effort: Balanced

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.64%. Comparing base (b226ed2) to head (bc40dd9).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4361      +/-   ##
==========================================
+ Coverage   97.62%   97.64%   +0.02%     
==========================================
  Files        1338     1343       +5     
  Lines      150250   151315    +1065     
  Branches     5125     5188      +63     
==========================================
+ Hits       146676   147758    +1082     
+ Misses       2272     2246      -26     
- Partials     1302     1311       +9     
🚀 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.

Rewrite only type arguments in crefs bound to the type being renamed, and cover unrelated cref placeholders, method crefs, and generated partial declarations.

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

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

Cref rewriting can invalidate valid references by changing unrelated placeholders or introducing placeholder-name collisions.

2 open issues

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 20, 2026 02:12
@AArnott

AArnott commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

The Codecov report shown here is for an earlier head (1ed73b8), before the subsequent regression-test commits. The latest changes include tests for both reported cases; I reviewed the coverage concern and no additional change is needed based on this stale report.

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

Rename edge cases can introduce duplicate type parameters or break valid documentation references.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Avoid rewriting parameter-list type placeholders

src/​StyleCop.Analyzers.CodeFixes/​NamingRules/​SA1314CodeFixProvider.cs:227

This also matches constructed types in cref parameter lists. In Foo<IDENT>, a valid cref="Other{IDENT}.M(Foo{IDENT})" can refer to Other<T>.M(Foo<T>); the signature's IDENT then refers to the placeholder declared by Other{IDENT}, not Foo's source type parameter. Rewriting only Foo{IDENT} to Foo{TIDENT} breaks that binding. Exclude parameter-list types from this manual rewrite, leave genuine source-symbol references there to the renamer, and add this regression case.

2 resolved since last review

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 20, 2026 02:22

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

Cref rewriting can alter unrelated references and miss generic-method placeholder collisions, breaking member resolution.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Reserve placeholder names across generic methods and nested types

src/​StyleCop.Analyzers.CodeFixes/​NamingRules/​SA1314CodeFixProvider.cs:174

The new collision check covers sibling type placeholders but excludes generic-method placeholders in the same cref. For Foo<IDENT> containing M<TMethod>(IDENT first, TMethod second), Foo{IDENT}.M{TIDENT}(IDENT,TIDENT) still allows the replacement name TIDENT. This merges the class and method placeholders, so the cref no longer distinguishes the two parameter types and can fail member resolution. Reserve competing placeholder declarations across the entire affected cref, including generic methods and nested types, and add a regression test for this case.

Medium severity Preserve generic type references in cref parameter lists

src/​StyleCop.Analyzers.CodeFixes/​NamingRules/​SA1314CodeFixProvider.cs:234

Generic type arguments inside a cref parameter list are references, not placeholder declarations. Inside Foo<IDENT>, a cref Other{IDENT}.M(Foo{IDENT}) can refer to Other<T>.M(Foo<T>). This filter changes the inner argument to TIDENT even though it refers to Other's independent placeholder, breaking the member reference. Exclude cref parameter lists from the manual rewrite and let the semantic renamer handle references there. Add a regression test that preserves this cref.

1 resolved since last review

Review effort: Balanced

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

Rule SA1314: Documentation fix missed out

2 participants