Go

Go

Made by DeepSource

Nested if can be replaced with else if CRT-A0011

Anti-pattern
Major
Autofix

A single nested if inside an else block can be replaced with an else if.

It's better to have as little nesting as possible. Hence, it's cleaner to replace a single nested if inside an else with an else-if.

Bad practice

if cond1 {
    // do something
} else {
    if x := cond2; x {
        // do something else
    }
}

Recommended

if cond1 {
    // do something
} else if x := cond2; x {
    // do something else
}