zero

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 9 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "zero",
	Doc:  doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL