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

New rule S6605: Collection-specific "Exists" method should be used instead of the "Any" extension #7160

Merged
merged 37 commits into from
May 15, 2023

Conversation

cristian-ambrosini-sonarsource
Copy link
Contributor

Fixes #7123

"id": "S6605",
"message": "Collection-specific "Exists" method should be used instead of the "Any" extension.",
"location": {
"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"id": "S6605",
"message": "Collection-specific "Exists" method should be used instead of the "Any" extension.",
"location": {
"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"id": "S6605",
"message": "Collection-specific "Exists" method should be used instead of the "Any" extension.",
"location": {
"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"id": "S6605",
"message": "Collection-specific "Exists" method should be used instead of the "Any" extension.",
"location": {
"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"id": "S6605",
"message": "Collection-specific "Exists" method should be used instead of the "Any" extension.",
"location": {
"uri": "sources\Nancy\src\Nancy.ViewEngines.Spark\NancyViewFolder.cs",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"id": "S6605",
"message": "Collection-specific "Exists" method should be used instead of the "Any" extension.",
"location": {
"uri": "sources\akka.net\src\core\Akka\Actor\ActorProducerPipeline.cs",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"id": "S6605",
"message": "Collection-specific "Exists" method should be used instead of the "Any" extension.",
"location": {
"uri": "sources\akka.net\src\core\Akka\Actor\ActorProducerPipeline.cs",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"id": "S6605",
"message": "Collection-specific "Exists" method should be used instead of the "Any" extension.",
"location": {
"uri": "sources\akka.net\src\core\Akka\Event\EventBus.cs",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"id": "S6605",
"message": "Collection-specific "Exists" method should be used instead of the "Any" extension.",
"location": {
"uri": "sources\akka.net\src\contrib\cluster\Akka.Cluster.Tools\Singleton\OldestChangedBuffer.cs",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks way better, I can see the finish line!


intList.Any(x => x.GetType() == typeof(int)); // Noncompliant
intList.Any(x => x.GetType().Equals(typeof(int))); // Noncompliant FP
intList.Any(x => MyIntCheck(x)); // Noncompliant

Choose a reason for hiding this comment

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

Add this type of check but without the argument for completion sake:

intList.Any(MyIntCheck) // Noncompliant

same for string check

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! 🥇
Left a very minor comment, feel free to merge afterwards! 🤗
I think the implementation covers most of the equality scenarios, and I imagine the Contains rule will be as much fun to implement as this one!
Congratulations!

@sonarcloud
Copy link

sonarcloud bot commented May 15, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented May 15, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

95.8% 95.8% Coverage
0.3% 0.3% Duplication

@cristian-ambrosini-sonarsource cristian-ambrosini-sonarsource merged commit 46e0e37 into master May 15, 2023
22 checks passed
@cristian-ambrosini-sonarsource cristian-ambrosini-sonarsource deleted the cristian/S6605 branch May 15, 2023 06:31
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.

New rule S6605: Collection-specific "Exists" method should be used instead of the "Any" extension
3 participants