Skip to content

Add S6605 - Use Exists Instead of Any#123

Merged
vdebellabre merged 2 commits into
green-code-initiative:mainfrom
QzLP2P:feat/S6605/linqAnyVsExist
May 20, 2026
Merged

Add S6605 - Use Exists Instead of Any#123
vdebellabre merged 2 commits into
green-code-initiative:mainfrom
QzLP2P:feat/S6605/linqAnyVsExist

Conversation

@QzLP2P
Copy link
Copy Markdown
Contributor

@QzLP2P QzLP2P commented May 20, 2026

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new Roslyn analyzer/code fix rule (GCI6605) that recommends using List<T>.Exists(predicate) instead of LINQ Enumerable.Any(predicate) when the receiver is a List<T> (or derived), with accompanying unit tests and a sandbox example.

Changes:

  • Added GCI6605 analyzer to detect list.Any(predicate) calls on List<T>/derived types (excluding expression-tree contexts).
  • Added a code fix to replace Any with Exists.
  • Added unit tests for positive/negative scenarios and a sandbox file demonstrating the rule.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Creedengo.Core/Analyzers/GCI6605.UseExistsInsteadOfAny.cs Adds analyzer logic and diagnostic metadata for GCI6605.
src/Creedengo.Core/Analyzers/GCI6605.UseExistsInsteadOfAny.Fixer.cs Adds code fix provider to rewrite Any to Exists.
src/Creedengo.Core/Models/Rule.cs Registers the new rule ID constant.
src/Creedengo.Tests/Tests/GCI6605.UseExistsInsteadOfAny.Tests.cs Adds test coverage for the new analyzer + fixer.
src/Creedengo.Sandbox/S6605Sandbox.cs Adds a sandbox snippet showcasing before/after usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Creedengo.Core/Analyzers/GCI6605.UseExistsInsteadOfAny.Fixer.cs Outdated
Comment thread src/Creedengo.Core/Analyzers/GCI6605.UseExistsInsteadOfAny.cs Outdated
Comment thread src/Creedengo.Tests/Tests/GCI6605.UseExistsInsteadOfAny.Tests.cs
- Fixer: use SimpleNameSyntax instead of IdentifierNameSyntax to handle
  both Any and Any<T> (GenericNameSyntax) cases
- Description: fix wording to mention enumerator allocation and interface
  dispatch instead of incorrect delegate allocation claim
- Tests: add AnyWithExplicitTypeArgumentAsync for GenericNameSyntax coverage
@vdebellabre vdebellabre merged commit 5c785d0 into green-code-initiative:main May 20, 2026
1 check passed
@QzLP2P QzLP2P deleted the feat/S6605/linqAnyVsExist branch May 20, 2026 13:04
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.

3 participants