indent-error-flow
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”...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 {...Configuration
Section titled “Configuration”go: lint: rules: indent-error-flow: warn # off (default), warn, errorEnabled by the presets: go/revive.
Suppress one line with sudsy-disable-next-line indent-error-flow in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| revive | indent-error-flow |
full |