Add linter asasalint
to lint pass []any as any (#2968)
This commit is contained in:
parent
e60937a179
commit
b415402720
@ -107,6 +107,22 @@ output:
|
||||
|
||||
# All available settings of specific linters.
|
||||
linters-settings:
|
||||
asasalint:
|
||||
# To specify a set of function names to exclude.
|
||||
# The values are merged with the builtin exclusions.
|
||||
# The builtin exclusions can be disabled by setting `use-builtin-exclusions` to `false`.
|
||||
# Default: ["^(fmt|log|logger)\.(Print|Fprint|Sprint|Fatal|Panic|Error|Warn|Warning|Info|Debug)(|f|ln)$"]
|
||||
exclude:
|
||||
- Append
|
||||
- \.Wrapf
|
||||
# To enable/disable the asasalint builtin exclusions of function names.
|
||||
# See the default value of `exclude` to get the builtin exclusions.
|
||||
# Default: true
|
||||
use-builtin-exclusions: false
|
||||
# Ignore *_test.go files.
|
||||
# Default: false
|
||||
ignore-test: true
|
||||
|
||||
bidichk:
|
||||
# The following configurations check for all mentioned invisible unicode runes.
|
||||
# All runes are enabled by default.
|
||||
@ -1823,6 +1839,7 @@ linters:
|
||||
# Enable specific linter
|
||||
# https://golangci-lint.run/usage/linters/#enabled-by-default-linters
|
||||
enable:
|
||||
- asasalint
|
||||
- asciicheck
|
||||
- bidichk
|
||||
- bodyclose
|
||||
@ -1922,6 +1939,7 @@ linters:
|
||||
# Disable specific linter
|
||||
# https://golangci-lint.run/usage/linters/#disabled-by-default-linters--e--enable
|
||||
disable:
|
||||
- asasalint
|
||||
- asciicheck
|
||||
- bidichk
|
||||
- bodyclose
|
||||
|
1
go.mod
1
go.mod
@ -11,6 +11,7 @@ require (
|
||||
github.com/GaijinEntertainment/go-exhaustruct/v2 v2.2.0
|
||||
github.com/OpenPeeDeeP/depguard v1.1.0
|
||||
github.com/alexkohler/prealloc v1.0.0
|
||||
github.com/alingse/asasalint v0.0.10
|
||||
github.com/ashanbrown/forbidigo v1.3.0
|
||||
github.com/ashanbrown/makezero v1.1.1
|
||||
github.com/bkielbasa/cyclop v1.2.0
|
||||
|
2
go.sum
generated
2
go.sum
generated
@ -70,6 +70,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||
github.com/alexkohler/prealloc v1.0.0 h1:Hbq0/3fJPQhNkN0dR95AVrr6R7tou91y0uHG5pOcUuw=
|
||||
github.com/alexkohler/prealloc v1.0.0/go.mod h1:VetnK3dIgFBBKmg0YnD9F9x6Icjd+9cvfHR56wJVlKE=
|
||||
github.com/alingse/asasalint v0.0.10 h1:qqGPDTV0ff0tWHN/nnIlSdjlU/EwRPaUY4SfpE1rnms=
|
||||
github.com/alingse/asasalint v0.0.10/go.mod h1:nCaoMhw7a9kSJObvQyVzNTPBDbNpdocqrSP7t/cW5+I=
|
||||
github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
|
||||
github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q=
|
||||
|
@ -7,6 +7,9 @@ import (
|
||||
)
|
||||
|
||||
var defaultLintersSettings = LintersSettings{
|
||||
Asasalint: AsasalintSettings{
|
||||
UseBuiltinExclusions: true,
|
||||
},
|
||||
Decorder: DecorderSettings{
|
||||
DecOrder: []string{"type", "const", "var", "func"},
|
||||
DisableDecNumCheck: true,
|
||||
@ -113,6 +116,7 @@ var defaultLintersSettings = LintersSettings{
|
||||
}
|
||||
|
||||
type LintersSettings struct {
|
||||
Asasalint AsasalintSettings
|
||||
BiDiChk BiDiChkSettings
|
||||
Cyclop Cyclop
|
||||
Decorder DecorderSettings
|
||||
@ -184,6 +188,12 @@ type LintersSettings struct {
|
||||
Custom map[string]CustomLinterSettings
|
||||
}
|
||||
|
||||
type AsasalintSettings struct {
|
||||
Exclude []string `mapstructure:"exclude"`
|
||||
UseBuiltinExclusions bool `mapstructure:"use-builtin-exclusions"`
|
||||
IgnoreTest bool `mapstructure:"ignore-test"`
|
||||
}
|
||||
|
||||
type BiDiChkSettings struct {
|
||||
LeftToRightEmbedding bool `mapstructure:"left-to-right-embedding"`
|
||||
RightToLeftEmbedding bool `mapstructure:"right-to-left-embedding"`
|
||||
|
30
pkg/golinters/asasalint.go
Normal file
30
pkg/golinters/asasalint.go
Normal file
@ -0,0 +1,30 @@
|
||||
package golinters
|
||||
|
||||
import (
|
||||
"github.com/alingse/asasalint"
|
||||
"golang.org/x/tools/go/analysis"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/config"
|
||||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
|
||||
)
|
||||
|
||||
func NewAsasalint(setting *config.AsasalintSettings) *goanalysis.Linter {
|
||||
cfg := asasalint.LinterSetting{}
|
||||
if setting != nil {
|
||||
cfg.Exclude = setting.Exclude
|
||||
cfg.NoBuiltinExclusions = !setting.UseBuiltinExclusions
|
||||
cfg.IgnoreTest = setting.IgnoreTest
|
||||
}
|
||||
|
||||
a, err := asasalint.NewAnalyzer(cfg)
|
||||
if err != nil {
|
||||
linterLogger.Fatalf("asasalint: create analyzer: %v", err)
|
||||
}
|
||||
|
||||
return goanalysis.NewLinter(
|
||||
a.Name,
|
||||
a.Doc,
|
||||
[]*analysis.Analyzer{a},
|
||||
nil,
|
||||
).WithLoadMode(goanalysis.LoadModeTypesInfo)
|
||||
}
|
@ -101,6 +101,7 @@ func enableLinterConfigs(lcs []*linter.Config, isEnabled func(lc *linter.Config)
|
||||
//nolint:funlen
|
||||
func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
|
||||
var (
|
||||
asasalintCfg *config.AsasalintSettings
|
||||
bidichkCfg *config.BiDiChkSettings
|
||||
cyclopCfg *config.Cyclop
|
||||
decorderCfg *config.DecorderSettings
|
||||
@ -171,6 +172,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
|
||||
)
|
||||
|
||||
if m.cfg != nil {
|
||||
asasalintCfg = &m.cfg.LintersSettings.Asasalint
|
||||
bidichkCfg = &m.cfg.LintersSettings.BiDiChk
|
||||
cyclopCfg = &m.cfg.LintersSettings.Cyclop
|
||||
decorderCfg = &m.cfg.LintersSettings.Decorder
|
||||
@ -266,6 +268,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
|
||||
// The linters are sorted in the alphabetical order (case-insensitive).
|
||||
// When a new linter is added the version in `WithSince(...)` must be the next minor version of golangci-lint.
|
||||
lcs := []*linter.Config{
|
||||
linter.NewConfig(golinters.NewAsasalint(asasalintCfg)).
|
||||
WithSince("1.47.0").
|
||||
WithPresets(linter.PresetBugs).
|
||||
WithLoadForGoAnalysis().
|
||||
WithURL("https://github.com/alingse/asasalint"),
|
||||
|
||||
linter.NewConfig(golinters.NewAsciicheck()).
|
||||
WithSince("v1.26.0").
|
||||
WithPresets(linter.PresetBugs, linter.PresetStyle).
|
||||
|
20
test/testdata/asasalint.go
vendored
Normal file
20
test/testdata/asasalint.go
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
//golangcitest:args -Easasalint
|
||||
package testdata
|
||||
|
||||
import "fmt"
|
||||
|
||||
func getArgsLength(args ...interface{}) int {
|
||||
// this line will not report as error
|
||||
fmt.Println(args)
|
||||
return len(args)
|
||||
}
|
||||
|
||||
func checkArgsLength(args ...interface{}) int {
|
||||
return getArgsLength(args) // ERROR `pass \[\]any as any to func getArgsLength func\(args \.\.\.interface\{\}\)`
|
||||
}
|
||||
|
||||
func someCall() {
|
||||
var a = []interface{}{1, 2, 3}
|
||||
fmt.Println(checkArgsLength(a...) == getArgsLength(a)) // ERROR `pass \[\]any as any to func getArgsLength func\(args \.\.\.interface\{\}\)`
|
||||
fmt.Println(checkArgsLength(a...) == getArgsLength(a...))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user