Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add zero linter#3529

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
leonklingele wants to merge1 commit intogolangci:master
base:master
Choose a base branch
Loading
fromleonklingele:feat-add-zero
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions.golangci.reference.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2096,6 +2096,7 @@ linters:
- whitespace
- wrapcheck
- wsl
- zero

# Enable all available linters.
# Default: false
Expand DownExpand Up@@ -2206,6 +2207,7 @@ linters:
- whitespace
- wrapcheck
- wsl
- zero

# Enable presets.
# https://golangci-lint.run/usage/linters
Expand Down
1 change: 1 addition & 0 deletionsgo.mod
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,6 +45,7 @@ require (
github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8
github.com/gostaticanalysis/forcetypeassert v0.1.0
github.com/gostaticanalysis/nilerr v0.1.1
github.com/gostaticanalysis/zero v0.1.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-version v1.6.0
github.com/hexops/gotextdiff v1.0.3
Expand Down
2 changes: 2 additions & 0 deletionsgo.sum
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

19 changes: 19 additions & 0 deletionspkg/golinters/zero.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
package golinters

import (
"github.com/gostaticanalysis/zero"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

func NewZero() *goanalysis.Linter {
a := zero.Analyzer

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
5 changes: 5 additions & 0 deletionspkg/lint/lintersdb/manager.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -872,6 +872,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetStyle).
WithURL("https://github.com/bombsimon/wsl"),

linter.NewConfig(golinters.NewZero()).
WithSince("v1.51.0").
WithPresets(linter.PresetBugs).
WithURL("https://github.com/gostaticanalysis/zero"),

// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
linter.NewConfig(golinters.NewNoLintLint(noLintLintCfg)).
WithSince("v1.26.0").
Expand Down
35 changes: 35 additions & 0 deletionstest/testdata/zero.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
//golangcitest:args -Ezero
package testdata

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

please fix the typo inshould


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"
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"

{
n, _ := func() (int, int) { return 0, 0 }() // OK
_ = n
}

{
var n, _ = func() (int, int) { return 0, 0 }() // OK
_ = n
}
}

[8]ページ先頭

©2009-2025 Movatter.jp