Skip to content

indent-error-flow

Gostyleno fixdefault: offgo/revive

An else block after an if block that ends in return: the code of the else can follow the if. An else if is left alone.

When the if block ends in return, the else only adds a level of indentation to the code that follows. Without it the normal path stays at the left edge and the early return reads as a guard, which is the Go way of handling errors first. Removing the else does not change what the function does.

To fix, delete else and move its block after the if.

Reported
...
func f(a bool) int {
if a {
return 1
} else {
return 2
}
}
...
}
if x := g(); x {
return 1
} else {
g()
}
if a {
...
if a {
if b {
return 1
} else {
return 2
}
} else {
...
go:
lint:
rules:
indent-error-flow: warn # off (default), warn, error

Enabled by the presets: go/revive.

Suppress one line with sudsy-disable-next-line indent-error-flow in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
revive indent-error-flow full