mneverov / unc

unc is a linter that reports a c-style nil checks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unc

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

Install

go get github.com/mneverov/unc

Run

unc ./...

go/analysis flags are available:

unc -h

To fix reported issues run:

unc -fix ./...

Example

func foo() {
	var err error

	if nil != err {
	}
}
unc ./...
foo.go:7:5: lhs nil  

About

unc is a linter that reports a c-style nil checks

License:MIT License


Languages

Language:Go 100.0%