Go

Go

By DeepSource

Redundant else-blocks can be eliminatedRVV-A0009

Anti-pattern
Has Autofix

To ensure as little nesting as possible (to improve code readability), the else blocks that can be eliminated should be removed. For example, if the if block contains a return statement, the else block can be omitted entirely.

For example,

for {
    if ok := f(); ok {
        a := 1
        continue
    } else {
        return "it's NOT okay!"
    }
}

can be rewritten as:

for {
    if ok := f(); ok {
        a := 1
        continue
    }
    return "it's NOT okay!"
}