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

Enable new analyzer CA1868: 'Unnecessary call to 'Contains' for sets' and fix findings #89652

Merged
merged 3 commits into from Jul 29, 2023

Conversation

mpidash
Copy link
Contributor

@mpidash mpidash commented Jul 28, 2023

The new analyzer CA1868: 'Unnecessary call to 'Contains' for sets'
checks when an Add or Remove is guarded by Contains.

This commit removes these calls to Contains.
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jul 28, 2023
@ghost
Copy link

ghost commented Jul 28, 2023

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

Issue Details

See dotnet/roslyn-analyzers#6767 and #85490.

Author: mpidash
Assignees: -
Labels:

area-Meta

Milestone: -

@@ -483,6 +483,9 @@ dotnet_diagnostic.CA1863.severity = suggestion
# CA1864: Prefer the 'IDictionary.TryAdd(TKey, TValue)' method
dotnet_diagnostic.CA1864.severity = warning

# CA1868: Unnecessary call to 'Contains' for sets
dotnet_diagnostic.CA1868.severity = warning
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a corresponding entry to the .test.globalconfig file? That one would be at level none.

Comment on lines 188 to 190
if (!candidates.Add(candidatePart))
{
alreadyProcessed = true;
Copy link
Member

Choose a reason for hiding this comment

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

alreadyProcessed |= !candidates.Add(candidatePart);

?

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Thanks!

@marek-safar marek-safar merged commit 4ed3550 into dotnet:main Jul 29, 2023
176 of 180 checks passed
@mpidash mpidash deleted the remove-guarded-set-calls branch July 29, 2023 13:01
@dotnet dotnet locked as resolved and limited conversation to collaborators Aug 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Meta community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants