Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Analyzer: Prefer .Length/Count/IsEmpty over Any() #6236
Analyzer: Prefer .Length/Count/IsEmpty over Any() #6236
Changes from 14 commits
846ed66
39ddb18
3502244
f466a9e
0d6689e
061c15d
bae2acb
2df3b4d
ca68478
92675a6
1e36aac
639af3d
cc86232
bc89cba
e825483
36d65f0
f99b71f
aa5b25e
9a0cb96
0dcf2a6
5ed99ad
9aac134
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diagnostics quite similar, do not see need to handle them separately, probably better to be one diagnostic?
CC @stephentoub @mavasani
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolving this comment as:
IEnumerable.Any()
that does count/length check in the implementation I would prefer to use Any() over Count or Length check, therefore it seems one might prefer to suppress one of them over the other.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unresolving this as if we restrict to
Enumerable.Any()
only there will be no need to handle these warnings separately.@CollinAlpert lets use only one ID for each DiagnosticDecriptors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this approach is that we miss things like https://learn.microsoft.com/en-us/dotnet/api/system.linq.immutablearrayextensions.any?view=net-7.0#system-linq-immutablearrayextensions-any-1(system-collections-immutable-immutablearray((-0)))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CollinAlpert I see. Then consider not adding anything to compilation start, but check the method correctly.
The code should be language-agnostic (no C#/VB checks), and parameter name shouldn't be checked. Just check method name, whether it's extension method, whether it has a single parameter, and whether its return type is boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember having problems with eliminating language checks, as I believe Roslyn considers
Any
to be an extension method in C# and not an extension method in VB.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CollinAlpert That suggestion to use
ReducedFrom
ifMethodKind
isReducedExtension
should probably fix the problems you were seeing.