Feuermagier / autograder

Automatic grading of student's Java code
MIT License
13 stars 7 forks source link

Suggest `SomeListing.of(1, 2, 6, ...).contains(c)` in place of `c == 1 || c == 2 || c == 6 ....` #555

Open Luro02 opened 1 week ago

Luro02 commented 1 week ago

What it does

Simplifies complex boolean expressions into shorter ones that are easier to read.

Some things to be careful of:

Lint Name

USE_LISTING_CONTAINS

Category

complexity

Example

class Test {
    boolean isValid(char ch) {
        return ch == 'N' || ch == 'S' || ch == 'O' || ch == 'W' || ch == 'n' || ch == 's' || ch == 'o' || ch == 'w';
    }
}

Could be written as:

class Test {
    boolean isValid(char ch) {
        return List.of('N', 'S', 'O', 'W', 'n', 's', 'o', 'w').contains(ch);
    }
}