You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like the check for unnecessaryDefer only checks if the defer statement is the last statement in a block, no matter what block it is. Because of this it's not possible to set conditional defer statements.
Noticed this when a build in golangci-lint failed. Here's a smaller example to reproduce.
package main
import"fmt"funcmain() {
iftrue {
deferfunc() {
fmt.Println("something was true")
}()
}
fmt.Println("more code before return")
}
$ gocritic check -enable='unnecessaryDefer' ./...
./main.go:7:3: unnecessaryDefer: defer func(){...}(...) is placed just before return
The text was updated successfully, but these errors were encountered:
By keeping track of the block type we can differentiate between
functions and other blocks. This way we can enure that only blocks
ending with explicit return or end of functions yelds warnings.
By keeping track of the block type we can differentiate between
functions and other blocks. This way we can enure that only blocks
ending with explicit return or end of functions yelds warnings.
It seems like the check for
unnecessaryDefer
only checks if the defer statement is the last statement in a block, no matter what block it is. Because of this it's not possible to set conditional defer statements.Noticed this when a build in
golangci-lint
failed. Here's a smaller example to reproduce.The text was updated successfully, but these errors were encountered: