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

feat: Add CollectionIsEmptyProcessor (SonarSource rule 1155) #571

Merged
merged 3 commits into from
Jun 16, 2021

Conversation

fermadeiral
Copy link
Collaborator

This PR adds a processor for the rule Collection.isEmpty() should be used to test for emptiness.

Example repair:

- if (myCollection.size() == 0) {  // Noncompliant
+ if (myCollection.isEmpty()) {
...  
- if (myCollection.size() != 0) {  // Noncompliant
+ if (!myCollection.isEmpty()) {

@fermadeiral
Copy link
Collaborator Author

The method not(CtExpression<T> expr) is a copy from another processor. We should have something like SpoonUtils to keep these utility methods together and accessible to all processors. I believe this should be handled in a different PR though.

Copy link
Collaborator

@slarse slarse left a comment

Choose a reason for hiding this comment

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

A raw type cast, otherwise LGTM!

The method not(CtExpression<T> expr) is a copy from another processor. We should have something like SpoonUtils to keep these utility methods together and accessible to all processors. I believe this should be handled in a different PR though.

Agree, we should have a utility class with static methods for this kind of thing.

@slarse slarse merged commit d8bd98d into master Jun 16, 2021
@slarse slarse deleted the add-processor-for-s1155 branch June 16, 2021 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants