Skip to content

superfluous-else

Gostyleno fixdefault: offgo/revive

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.

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.

Reported
...
for {
if a {
continue
} else {
g()
}
if a {
...
if a {
g()
goto end
} else {
g()
}
if a {
...
go:
lint:
rules:
superfluous-else: warn # off (default), warn, error

Enabled by the presets: go/revive.

Suppress one line with sudsy-disable-next-line superfluous-else 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 superfluous-else full