Skip to content

Analyzer: zero finds unnecessary assignment which zero value assigns to a variable

License

Notifications You must be signed in to change notification settings

gostaticanalysis/zero

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zero

pkg.go.dev

zero finds unnecessary assignment which zero value assigns to a variable.

package a

var _ string = "" // want "shoud not assign zero value"

func _() {
	n := 0 // want "shoud not assign zero value"
	_ = n

	var _ []int = nil     // want "shoud not assign zero value"
	var _ []int = []int{} // OK
	m := int32(0)         // OK
	_ = m
	var _ *int = nil            // want "shoud not assign zero value"
	var _ struct{} = struct{}{} // want "shoud not assign zero value"
	var _, _ int                // OK
	var _, _ int = 0, 1         // want "shoud not assign zero value"
	var _, _ int = 1, 2         // OK
	var _, _ int = 1 - 1, 2 - 2 // want "shoud not assign zero value" "shoud not assign zero value"
	var _ bool = false          // want "shoud not assign zero value"
	var _ bool = true           // OK

	type T struct{ N int }
	var _ T = T{} // want "shoud not assign zero value"
}

Install

You can get zero by go install command (Go 1.16 and higher).

$ go install github.com/gostaticanalysis/zero/cmd/zero@latest

How to use

zero run with go vet as below when Go is 1.12 and higher.

$ go vet -vettool=$(which zero) ./...

Analyze with golang.org/x/tools/go/analysis

You can use zero.Analyzer with unitchecker.

About

Analyzer: zero finds unnecessary assignment which zero value assigns to a variable

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages