8000 feat: add linters onlyany, visibilityorder by dorfire · Pull Request #3197 · golangci/golangci-lint · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add linters onlyany, visibilityorder #3197

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,7 @@ linters:
- nonamedreturns
- nosnakecase
- nosprintfhostport
- onlyany
- paralleltest
- prealloc
- predeclared
Expand All @@ -2022,6 +2023,7 @@ linters:
- usestdlibvars
- varcheck
- varnamelen
- visibilityorder
- wastedassign
- whitespace
- wrapcheck
Expand Down Expand Up @@ -2103,6 +2105,7 @@ linters:
- nonamedreturns
- nosnakecase
- nosprintfhostport
- onlyany
- paralleltest
- prealloc
- predeclared
Expand All @@ -2128,6 +2131,7 @@ linters:
- usestdlibvars
- varcheck
- varnamelen
- visibilityorder
- wastedassign
- whitespace
- wrapcheck
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/chavacava/garif v0.0.0-20220630083739-93517212f375 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dorfire/go-analyzers v0.0.1
github.com/ettle/strcase v0.1.1 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
Expand Down Expand Up @@ -185,3 +186,5 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect
)

require github.com/samber/lo v1.21.0 // indirect
9 changes: 5 additions & 4 deletions go.sum

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

17 changes: 17 additions & 0 deletions pkg/golinters/onlyany.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package golinters

import (
"github.com/dorfire/go-analyzers/src/onlyany"
"golang.org/x/tools/go/analysis"

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

func NewOnlyAny() *goanalysis.Linter {
return goanalysis.NewLinter(
onlyany.Analyzer.Name,
onlyany.Analyzer.Doc,
[]*analysis.Analyzer{onlyany.Analyzer},
nil,
).WithLoadMode(goanalysis.LoadModeSyntax)
}
17 changes: 17 additions & 0 deletions pkg/golinters/visibilityorder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package golinters

import (
"github.com/dorfire/go-analyzers/src/visibilityorder"
"golang.org/x/tools/go/analysis"

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

func NewVisibilityOrder() *goanalysis.Linter {
return goanalysis.NewLinter(
visibilityorder.Analyzer.Name,
visibilityorder.Analyzer.Doc,
[]*analysis.Analyzer{visibilityorder.Analyzer},
nil,
).WithLoadMode(goanalysis.LoadModeSyntax)
}
10 changes: 10 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetStyle).
WithURL("https://github.com/stbenjam/no-sprintf-host-port"),

linter.NewConfig(golinters.NewOnlyAny()).
WithSince("v1.50.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/dorfire/go-analyzers"),

linter.NewConfig(golinters.NewParallelTest(parallelTestCfg)).
WithSince("v1.33.0").
WithLoadForGoAnalysis().
Expand Down Expand Up @@ -817,6 +822,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithLoadForGoAnalysis().
WithURL("https://github.com/blizzy78/varnamelen"),

linter.NewConfig(golinters.NewVisibilityOrder()).
WithSince("v1.50.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/dorfire/go-analyzers"),

linter.NewConfig(golinters.NewWastedAssign()).
WithSince("v1.38.0").
WithPresets(linter.PresetStyle).
Expand Down
9 changes: 9 additions & 0 deletions test/testdata/onlyany.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//golangcitest:args -Eonlyany
package testdata

import "fmt"

func onlyanyTest() {
var a interface{} // want `use any instead of an empty interface`
fmt.Print(a)
}
8 changes: 8 additions & 0 deletions test/testdata/visibilityorder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//golangcitest:args -Evisibilityorder
package testdata

func visibilityorderTest_UnexportedFunc() {
}

func VisibilityorderTest_ExportedFunc() { // want `exported symbol VisibilityorderTest_ExportedFunc appears after unexported symbol visibilityorderTest_UnexportedFunc`
}
0