Linter unc
reports c-style nil checks.
Null checks with null on the left hand side (lhs) were popular in C to avoid the following bug:
if (some_var = NULL) ...
In Go such syntax is invalid, and hence c-style nil checks should not be used.
if someVar = nil ...
syntax error: cannot use assignment (someVar) = (nil) as value
go get github.com/mneverov/unc
unc ./...
go/analysis
flags are available:
unc -h
To fix reported issues run:
unc -fix ./...
func foo() {
var err error
if nil != err {
}
}
unc ./...
foo.go:7:5: lhs nil