Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate unique name for CA1861 #7013

Merged
merged 2 commits into from
Oct 31, 2023
Merged

Conversation

CollinAlpert
Copy link
Contributor

The current implementation only considers the type's members when generating a name for the array. This PR extends the fixer to also consider method parameters and method locals.

Fixes #6981

@CollinAlpert CollinAlpert requested a review from a team as a code owner October 30, 2023 17:19
@codecov
Copy link

codecov bot commented Oct 30, 2023

Codecov Report

Merging #7013 (17bde3b) into main (b40db00) will increase coverage by 0.00%.
Report is 4 commits behind head on main.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #7013   +/-   ##
=======================================
  Coverage   96.42%   96.43%           
=======================================
  Files        1412     1412           
  Lines      336397   336432   +35     
  Branches    11114    11117    +3     
=======================================
+ Hits       324382   324425   +43     
+ Misses       9212     9205    -7     
+ Partials     2803     2802    -1     

if (containingMethod?.BlockBody is not null)
{
identifiers.AddRange(containingMethod.BlockBody.Locals.Select(l => l.Name));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like a good intermediate fix for the issue being fixed, though I do wish we had access to https://github.com/dotnet/roslyn/blob/main/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Utilities/NameGenerator.cs, which is not a public API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's stopping us from making it public or copying it?

@mavasani mavasani merged commit d3e5965 into dotnet:main Oct 31, 2023
11 checks passed
@CollinAlpert CollinAlpert deleted the issue-6981 branch October 31, 2023 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CA1861 code fix doesn't use unique name
2 participants