All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S6660.html Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version

Why is this an issue?

When if is the only statement in the else block, it is better to use else if because it simplifies the code and makes it more readable.

When using nested if statements, it can be difficult to keep track of the logic and understand the flow of the code. Using else if makes the code more concise and easier to follow.

if (condition1) {
    // ...
} else {
    if (condition2) {  // Noncompliant: 'if' statement is the only statement in the 'else' block
        // ...
    }
}


if (condition3) {
    // ...
} else {
    if (condition4) { // Noncompliant: 'if' statement is the only statement in the 'else' block
        // ...
    } else {
        // ...
    }
}

Fix your code by using else if if the nested if is the only statement in the else block.

if (condition1) {
    // ...
} else if (condition2) {
    // ...
}


if (condition3) {
    // ...
} else if (condition4) {
    // ...
} else {
    // ...
}

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy