superfluous-else
What it does
Section titled “What it does”An else block after an if block that ends in break, continue or goto: 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 break, continue or goto, control never reaches the else, so the else only indents the code that follows. Without it the code reads as a guard followed by the main path. Removing the else does not change what the loop does.
To fix, delete else and move its block after the if.
Example
Section titled “Example”... for { if a { continue } else { g() } if a {... if a { g() goto end } else { g() } if a {...Configuration
Section titled “Configuration”go: lint: rules: superfluous-else: warn # off (default), warn, errorEnabled by the presets: go/revive.
Suppress one line with sudsy-disable-next-line superfluous-else 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 | superfluous-else |
full |