Kotlin

Kotlin

Made by DeepSource

Found if statements that can be collapsed into one KT-W1048

Anti-pattern
Minor

Collapsing nested if statements into one improves code readability by making it more concise and easier to understand. It simplifies the logic, reduces cyclomatic complexity, and can lead to better performance. Debugging becomes easier, and code maintainability is enhanced. It is important to strike a balance between readability and line length while considering the overall code structure.

Bad Practice

val i = 1
if (i > 0) {
    if (i < 5) {
        println(i)
    }
}

Recommended

Merge the if statements to improve code readability.

val i = 1
if (i > 0 && i < 5) {
    println(i)
}

References