From 1b0c407402dc95acd245e905f4f1a343482eb4a0 Mon Sep 17 00:00:00 2001 From: alingse Date: Sun, 10 Jul 2022 15:30:16 +0800 Subject: [PATCH] fix pr review changes use interface{} (not any)for go 1.17 test fix interface\{\} --- .golangci.reference.yml | 5 +++-- pkg/config/linters_settings.go | 4 ++-- pkg/golinters/asasalint.go | 15 ++++++++------- test/testdata/asasalint.go | 11 ++++++----- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.golangci.reference.yml b/.golangci.reference.yml index 1c8ab3b94aa8..337291c2ec10 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -112,9 +112,10 @@ linters-settings: exclude: - Append - Log + # ignore found case in *_test.go file + ignore-in-test: false # if true, will disable the default exclude see https://github.com/alingse/asasalint/blob/main/asasalint.go#L15 like: Printf,Println,Errorf,Debugf ... - no_default_exclude: false - ignore_in_test: false + no-default-exclude: false bidichk: # The following configurations check for all mentioned invisible unicode runes. # All runes are enabled by default. diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 64ecc01836f4..39a76dcc4912 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -187,8 +187,8 @@ type LintersSettings struct { type AsasalintSettings struct { Exclude []string `mapstructure:"exclude"` - NoDefaultExclude bool `mapstructure:"no_default_exclude"` - IgnoreInTest bool `mapstructure:"ignore_in_test"` + IgnoreInTest bool `mapstructure:"ignore-in-test"` + NoDefaultExclude bool `mapstructure:"no-default-exclude"` } type BiDiChkSettings struct { diff --git a/pkg/golinters/asasalint.go b/pkg/golinters/asasalint.go index e3d0ac9cabbf..07d1f1112dc8 100644 --- a/pkg/golinters/asasalint.go +++ b/pkg/golinters/asasalint.go @@ -8,14 +8,15 @@ import ( "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" ) -func NewAsasalint(cfg *config.AsasalintSettings) *goanalysis.Linter { - setting := asasalint.LinterSetting{} - if cfg != nil { - setting.Exclude = cfg.Exclude - setting.NoDefaultExclude = cfg.NoDefaultExclude - setting.IgnoreInTest = cfg.IgnoreInTest +func NewAsasalint(setting *config.AsasalintSettings) *goanalysis.Linter { + cfg := asasalint.LinterSetting{} + if setting != nil { + cfg.Exclude = setting.Exclude + cfg.IgnoreInTest = setting.IgnoreInTest + cfg.NoDefaultExclude = setting.NoDefaultExclude } - a := asasalint.NewAnalyzer(setting) + + a := asasalint.NewAnalyzer(cfg) return goanalysis.NewLinter( a.Name, diff --git a/test/testdata/asasalint.go b/test/testdata/asasalint.go index ed2af407e9af..562e0a9f2a82 100644 --- a/test/testdata/asasalint.go +++ b/test/testdata/asasalint.go @@ -1,17 +1,18 @@ +//args: -Easasalint package testdata import "fmt" -func getArgsLength(args ...any) int { +func getArgsLength(args ...interface{}) int { return len(args) } -func checkArgsLength(args ...any) int { - return getArgsLength(args) +func checkArgsLength(args ...interface{}) int { + return getArgsLength(args) // ERROR `pass \[\]any as any to func getArgsLength func\(args \.\.\.interface\{\}\)` } func someCall() { - var a = []any{1, 2, 3} - fmt.Println(checkArgsLength(a...) == getArgsLength(a)) + 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...)) }