Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "zero" linter #3491

Open
leonklingele opened this issue Jan 18, 2023 · 0 comments · May be fixed by #3529
Open

Add "zero" linter #3491

leonklingele opened this issue Jan 18, 2023 · 0 comments · May be fixed by #3529
Labels
enhancement New feature or improvement linter: new Support new linter no decision No decision to fix or not

Comments

@leonklingele
Copy link
Member

Your feature request related to a problem? Please describe.

The zero linter 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"
}

https://github.com/gostaticanalysis/zero

Describe the solution you'd like.

Describe alternatives you've considered.

Additional context.

No response

@leonklingele leonklingele added the enhancement New feature or improvement label Jan 18, 2023
@ldez ldez added linter: new Support new linter no decision No decision to fix or not labels Jan 18, 2023
leonklingele added a commit to leonklingele/golangci-lint that referenced this issue Jan 31, 2023
@leonklingele leonklingele linked a pull request Jan 31, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement linter: new Support new linter no decision No decision to fix or not
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants