From cce8036bb31168b9b18216545d021ed889d50ecf Mon Sep 17 00:00:00 2001 From: Maik Schreiber Date: Sun, 24 Apr 2022 01:34:13 +0200 Subject: [PATCH 1/7] add consistent v0.1.0 --- .golangci.example.yml | 44 ++++++++++++++++++++++++ go.mod | 3 +- go.sum | 6 ++-- pkg/config/linters_settings.go | 18 ++++++++++ pkg/golinters/consistent.go | 63 ++++++++++++++++++++++++++++++++++ pkg/lint/lintersdb/manager.go | 8 +++++ test/testdata/consistent.go | 41 ++++++++++++++++++++++ 7 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 pkg/golinters/consistent.go create mode 100644 test/testdata/consistent.go diff --git a/.golangci.example.yml b/.golangci.example.yml index f2f97c92d877..3ffd1b3caa54 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -117,6 +117,50 @@ linters-settings: first-strong-isolate: false pop-directional-isolate: false + consistent: + # check function/method parameter type (ignore/explicit/implicit) + # Default: explicit + params: explicit + # check function/method return value types (ignore/explicit/implicit) + # Default: explicit + returns: explicit + # check function type parameter types (ignore/explicit/implicit) + # Default: explicit + type-params: explicit + # check single import declarations (ignore/bare/parens) + # Default: bare + single-imports: bare + # check allocations using new (ignore/literal/new) + # Default: literal + new-allocs: literal + # check allocations using make (ignore/literal/make) + # Default: literal + make-allocs: literal + # check upper/lowercase in hex literals (ignore/lower/upper) + # Default: lower + hex-lits: lower + # check range checks (ignore/left/center) + # Default: left + range-checks: left + # check AND-NOT expressions (ignore/and-not/and-comp) + # Default: and-not + and-nots: and-not + # check floating-point literals (ignore/explicit/implicit) + # Default: explicit + float-lits: explicit + # check len/cap checks (ignore/equal-zero/compare-zero/compare-one) + # Default: equal-zero + len-checks: equal-zero + # check switch case clauses (ignore/comma/or) + # Default: comma + switch-cases: comma + # check switch default clauses (ignore/last/first) + # Default: last + switch-defaults: last + # check labels against regexp ('' to ignore) + # Default: ^[a-z][a-zA-Z0-9]*$ + labels-regexp: ^[a-z][a-zA-Z0-9]*$ + cyclop: # The maximal code complexity to report. max-complexity: 10 diff --git a/go.mod b/go.mod index d9a1b2bf06a0..03c99160112e 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/ashanbrown/forbidigo v1.3.0 github.com/ashanbrown/makezero v1.1.1 github.com/bkielbasa/cyclop v1.2.0 + github.com/blizzy78/consistent v0.1.0 github.com/blizzy78/varnamelen v0.8.0 github.com/bombsimon/wsl/v3 v3.3.0 github.com/breml/bidichk v0.2.3 @@ -165,7 +166,7 @@ require ( golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e // indirect golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect - golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect + golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect google.golang.org/protobuf v1.28.0 // indirect diff --git a/go.sum b/go.sum index bc630033a124..a196c0142d8d 100644 --- a/go.sum +++ b/go.sum @@ -101,6 +101,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bkielbasa/cyclop v1.2.0 h1:7Jmnh0yL2DjKfw28p86YTd/B4lRGcNuu12sKE35sM7A= github.com/bkielbasa/cyclop v1.2.0/go.mod h1:qOI0yy6A7dYC4Zgsa72Ppm9kONl0RoIlPbzot9mhmeI= +github.com/blizzy78/consistent v0.1.0 h1:3UpV1fEH9uM8QpFaTXMG4uEqOwHdYO01tNJdGtRpCqg= +github.com/blizzy78/consistent v0.1.0/go.mod h1:CDYPPT427FpX/2la1OiepHYCZAvYHNavybBHSReL/Ug= github.com/blizzy78/varnamelen v0.8.0 h1:oqSblyuQvFsW1hbBHh1zfwrKe3kcSj0rnXkKzsQ089M= github.com/blizzy78/varnamelen v0.8.0/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k= github.com/bombsimon/wsl/v3 v3.3.0 h1:Mka/+kRLoQJq7g2rggtgQsjuI/K5Efd87WX96EWFxjM= @@ -1032,8 +1034,8 @@ golang.org/x/sys v0.0.0-20211105183446-c75c47738b0c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211213223007-03aa0b5f6827/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc= +golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 088223f0db62..ac62c00beb25 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -113,6 +113,7 @@ var defaultLintersSettings = LintersSettings{ type LintersSettings struct { BiDiChk BiDiChkSettings + Consistent ConsistentSettings Cyclop Cyclop Decorder DecorderSettings Depguard DepGuardSettings @@ -192,6 +193,23 @@ type BiDiChkSettings struct { PopDirectionalIsolate bool `mapstructure:"pop-directional-isolate"` } +type ConsistentSettings struct { + Params string `mapstructure:"params"` + Returns string `mapstructure:"returns"` + TypeParams string `mapstructure:"type-params"` + SingleImports string `mapstructure:"single-imports"` + NewAllocs string `mapstructure:"new-allocs"` + MakeAllocs string `mapstructure:"make-allocs"` + HexLits string `mapstructure:"hex-lits"` + RangeChecks string `mapstructure:"range-checks"` + AndNOTs string `mapstructure:"and-nots"` + FloatLits string `mapstructure:"float-lits"` + LenChecks string `mapstructure:"len-checks"` + SwitchCases string `mapstructure:"switch-cases"` + SwitchDefaults string `mapstructure:"switch-defaults"` + LabelsRegexp string `mapstructure:"labels-regexp"` +} + type Cyclop struct { MaxComplexity int `mapstructure:"max-complexity"` PackageAverage float64 `mapstructure:"package-average"` diff --git a/pkg/golinters/consistent.go b/pkg/golinters/consistent.go new file mode 100644 index 000000000000..3c448f66c019 --- /dev/null +++ b/pkg/golinters/consistent.go @@ -0,0 +1,63 @@ +package golinters + +import ( + "github.com/golangci/golangci-lint/pkg/config" + "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "golang.org/x/tools/go/analysis" + + "github.com/blizzy78/consistent" +) + +func NewConsistent(settings *config.ConsistentSettings) *goanalysis.Linter { + cfg := map[string]map[string]interface{}{} + + analyzer := consistent.NewAnalyzer() + + if settings != nil { + valueMapping := map[string]string{ + "and-comp": "andComp", + "and-not": "andNot", + "compare-one": "compareOne", + "compare-zero": "compareZero", + "equal-zero": "equalZero", + } + + analyzerCfg := map[string]interface{}{} + + set := func(key string, value string) { + if v, ok := valueMapping[value]; ok { + value = v + } + + if value == "" { + return + } + + analyzerCfg[key] = value + } + + set("params", settings.Params) + set("returns", settings.Returns) + set("typeParams", settings.TypeParams) + set("singleImports", settings.SingleImports) + set("newAllocs", settings.NewAllocs) + set("makeAllocs", settings.MakeAllocs) + set("hexLits", settings.HexLits) + set("rangeChecks", settings.RangeChecks) + set("andNOTs", settings.AndNOTs) + set("floatLits", settings.FloatLits) + set("lenChecks", settings.LenChecks) + set("switchCases", settings.SwitchCases) + set("switchDefaults", settings.SwitchDefaults) + set("labelsRegexp", settings.LabelsRegexp) + + cfg[analyzer.Name] = analyzerCfg + } + + return goanalysis.NewLinter( + analyzer.Name, + "checks that common constructs are used consistently", + []*analysis.Analyzer{analyzer}, + cfg, + ).WithLoadMode(goanalysis.LoadModeTypesInfo) +} diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index 86975c7a8665..654ed0461274 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -101,6 +101,7 @@ func enableLinterConfigs(lcs []*linter.Config, isEnabled func(lc *linter.Config) //nolint:funlen func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { var bidichkCfg *config.BiDiChkSettings + var consistentCfg *config.ConsistentSettings var cyclopCfg *config.Cyclop var decorderCfg *config.DecorderSettings var errchkjsonCfg *config.ErrChkJSONSettings @@ -134,6 +135,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { if m.cfg != nil { bidichkCfg = &m.cfg.LintersSettings.BiDiChk + consistentCfg = &m.cfg.LintersSettings.Consistent cyclopCfg = &m.cfg.LintersSettings.Cyclop errchkjsonCfg = &m.cfg.LintersSettings.ErrChkJSON decorderCfg = &m.cfg.LintersSettings.Decorder @@ -192,6 +194,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithURL("https://github.com/timakin/bodyclose"). WithNoopFallback(m.cfg), + linter.NewConfig(golinters.NewConsistent(consistentCfg)). + WithSince("v1.46.0"). + WithPresets(linter.PresetStyle). + WithLoadForGoAnalysis(). + WithURL("https://github.com/blizzy78/consistent"), + linter.NewConfig(golinters.NewContainedCtx()). WithSince("1.44.0"). WithPresets(linter.PresetStyle). diff --git a/test/testdata/consistent.go b/test/testdata/consistent.go new file mode 100644 index 000000000000..e57735c40ab9 --- /dev/null +++ b/test/testdata/consistent.go @@ -0,0 +1,41 @@ +//args: -Econsistent +package testdata + +import ( // ERROR "remove parens around single import declaration" + "strings" +) + +func consistent() { + _ = func(a, b int) {} // ERROR "declare the type of function arguments explicitly" + + _ = func() (a, b int) { return 1, 2 } // ERROR "declare the type of function return values explicitly" + + _ = new(strings.Builder) // ERROR "use zero-value literal instead of calling new" + + _ = make([]int, 0) // ERROR "use slice literal instead of calling make" + + _ = 0xABCDE // ERROR "use lowercase digits in hex literal" + + x := 5 + _ = 1 < x && x < 10 // ERROR "write common term in range expression on the left" + + _ = 1 & ^2 // ERROR "use AND-NOT operator instead of AND operator with complement expression" + + _ = .5 // ERROR "add zero before decimal point in floating-point literal" + + _ = len([]int{}) > 0 // ERROR `check if len is \(not\) 0 instead` + + switch { + case 1 < 2 || 3 < 4: // ERROR "separate cases with comma instead of using logical OR" + } + + switch { + default: // ERROR "move switch default clause to the end" + case 1 < 2: + } + +test_loop: // ERROR `change label to match regular expression: .*` + for { + break test_loop + } +} From c9b049c1019e8fb19c6bf41fae0f8e37e5e2d3d4 Mon Sep 17 00:00:00 2001 From: Maik Schreiber Date: Sun, 24 Apr 2022 01:43:27 +0200 Subject: [PATCH 2/7] fix linter warnings --- pkg/golinters/consistent.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/golinters/consistent.go b/pkg/golinters/consistent.go index 3c448f66c019..0d5f779e36b4 100644 --- a/pkg/golinters/consistent.go +++ b/pkg/golinters/consistent.go @@ -1,11 +1,11 @@ package golinters import ( - "github.com/golangci/golangci-lint/pkg/config" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/blizzy78/consistent" "golang.org/x/tools/go/analysis" - "github.com/blizzy78/consistent" + "github.com/golangci/golangci-lint/pkg/config" + "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" ) func NewConsistent(settings *config.ConsistentSettings) *goanalysis.Linter { From 64704985d4190d21fb5b60c4130ec9adbccd25ce Mon Sep 17 00:00:00 2001 From: Maik Schreiber Date: Sun, 24 Apr 2022 02:09:55 +0200 Subject: [PATCH 3/7] add consistent to list of available linters (enable/disable) --- .golangci.example.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.golangci.example.yml b/.golangci.example.yml index 3ffd1b3caa54..66b87e4cd829 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -1669,6 +1669,7 @@ linters: - asciicheck - bidichk - bodyclose + - consistent - contextcheck - cyclop - deadcode @@ -1759,6 +1760,7 @@ linters: - asciicheck - bidichk - bodyclose + - consistent - contextcheck - cyclop - deadcode From 03f0d423e6f92051ab04fd244a74f5c321429518 Mon Sep 17 00:00:00 2001 From: Maik Schreiber Date: Tue, 26 Apr 2022 01:26:10 +0200 Subject: [PATCH 4/7] bump consistent to v0.1.1 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index dbc3a437daac..4801b4320c03 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/ashanbrown/forbidigo v1.3.0 github.com/ashanbrown/makezero v1.1.1 github.com/bkielbasa/cyclop v1.2.0 - github.com/blizzy78/consistent v0.1.0 + github.com/blizzy78/consistent v0.1.1 github.com/blizzy78/varnamelen v0.8.0 github.com/bombsimon/wsl/v3 v3.3.0 github.com/breml/bidichk v0.2.3 diff --git a/go.sum b/go.sum index f6181c6a62c2..f0b6bb7efd3e 100644 --- a/go.sum +++ b/go.sum @@ -103,6 +103,8 @@ github.com/bkielbasa/cyclop v1.2.0 h1:7Jmnh0yL2DjKfw28p86YTd/B4lRGcNuu12sKE35sM7 github.com/bkielbasa/cyclop v1.2.0/go.mod h1:qOI0yy6A7dYC4Zgsa72Ppm9kONl0RoIlPbzot9mhmeI= github.com/blizzy78/consistent v0.1.0 h1:3UpV1fEH9uM8QpFaTXMG4uEqOwHdYO01tNJdGtRpCqg= github.com/blizzy78/consistent v0.1.0/go.mod h1:CDYPPT427FpX/2la1OiepHYCZAvYHNavybBHSReL/Ug= +github.com/blizzy78/consistent v0.1.1 h1:rOfb4gWI9cV0R8fJ7vEgQSJ3o7hkKTgsacoM38jkNZM= +github.com/blizzy78/consistent v0.1.1/go.mod h1:CDYPPT427FpX/2la1OiepHYCZAvYHNavybBHSReL/Ug= github.com/blizzy78/varnamelen v0.8.0 h1:oqSblyuQvFsW1hbBHh1zfwrKe3kcSj0rnXkKzsQ089M= github.com/blizzy78/varnamelen v0.8.0/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k= github.com/bombsimon/wsl/v3 v3.3.0 h1:Mka/+kRLoQJq7g2rggtgQsjuI/K5Efd87WX96EWFxjM= From 7897b17b46b67cae08c59df2cd9a18669c7f3808 Mon Sep 17 00:00:00 2001 From: Maik Schreiber Date: Fri, 19 Aug 2022 01:38:53 +0200 Subject: [PATCH 5/7] update consistent to v0.2.0 --- .golangci.reference.yml | 3 +++ go.mod | 6 +++--- go.sum | 12 ++++++------ pkg/config/linters_settings.go | 1 + pkg/golinters/consistent.go | 1 + test/testdata/consistent.go | 4 +++- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.golangci.reference.yml b/.golangci.reference.yml index d39f48b1cc89..856d57edbd86 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -176,6 +176,9 @@ linters-settings: # check switch default clauses (ignore/last/first) # Default: last switch-defaults: last + # check empty interfaces (ignore/any/iface) + # Default: any + empty-ifaces: any # check labels against regexp ('' to ignore) # Default: ^[a-z][a-zA-Z0-9]*$ labels-regexp: ^[a-z][a-zA-Z0-9]*$ diff --git a/go.mod b/go.mod index f0fedc70a3f0..07ef5f5f61dd 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/ashanbrown/forbidigo v1.3.0 github.com/ashanbrown/makezero v1.1.1 github.com/bkielbasa/cyclop v1.2.0 - github.com/blizzy78/consistent v0.1.1 + github.com/blizzy78/consistent v0.2.0 github.com/blizzy78/varnamelen v0.8.0 github.com/bombsimon/wsl/v3 v3.3.0 github.com/breml/bidichk v0.2.3 @@ -171,10 +171,10 @@ require ( go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.17.0 // indirect - golang.org/x/exp/typeparams v0.0.0-20220613132600-b0d781184e0d // indirect + golang.org/x/exp/typeparams v0.0.0-20220722155223-a9213eeb770e // indirect golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect - golang.org/x/sys v0.0.0-20220804214406-8e32c043e418 // indirect + golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect golang.org/x/text v0.3.7 // indirect google.golang.org/protobuf v1.28.0 // indirect gopkg.in/ini.v1 v1.66.6 // indirect diff --git a/go.sum b/go.sum index 4b4081b0d6e2..f92423957e1c 100644 --- a/go.sum +++ b/go.sum @@ -91,8 +91,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bkielbasa/cyclop v1.2.0 h1:7Jmnh0yL2DjKfw28p86YTd/B4lRGcNuu12sKE35sM7A= github.com/bkielbasa/cyclop v1.2.0/go.mod h1:qOI0yy6A7dYC4Zgsa72Ppm9kONl0RoIlPbzot9mhmeI= -github.com/blizzy78/consistent v0.1.1 h1:rOfb4gWI9cV0R8fJ7vEgQSJ3o7hkKTgsacoM38jkNZM= -github.com/blizzy78/consistent v0.1.1/go.mod h1:CDYPPT427FpX/2la1OiepHYCZAvYHNavybBHSReL/Ug= +github.com/blizzy78/consistent v0.2.0 h1:SPUhs1liTH4C3qJVef3UwCGxsD6DwRL7AX/3Z5wdsqQ= +github.com/blizzy78/consistent v0.2.0/go.mod h1:OH+Mtm6qYm8O5tuBspt3HkRgaHkI1xrxtdm/s+w5sxI= github.com/blizzy78/varnamelen v0.8.0 h1:oqSblyuQvFsW1hbBHh1zfwrKe3kcSj0rnXkKzsQ089M= github.com/blizzy78/varnamelen v0.8.0/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k= github.com/bombsimon/wsl/v3 v3.3.0 h1:Mka/+kRLoQJq7g2rggtgQsjuI/K5Efd87WX96EWFxjM= @@ -785,8 +785,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= -golang.org/x/exp/typeparams v0.0.0-20220613132600-b0d781184e0d h1:+W8Qf4iJtMGKkyAygcKohjxTk4JPsL9DpzApJ22m5Ic= -golang.org/x/exp/typeparams v0.0.0-20220613132600-b0d781184e0d/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= +golang.org/x/exp/typeparams v0.0.0-20220722155223-a9213eeb770e h1:7Xs2YCOpMlNqSQSmrrnhlzBXIE/bpMecZplbLePTJvE= +golang.org/x/exp/typeparams v0.0.0-20220722155223-a9213eeb770e/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -965,8 +965,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220702020025-31831981b65f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220804214406-8e32c043e418 h1:9vYwv7OjYaky/tlAeD7C4oC9EsPTlaFl1H2jS++V+ME= -golang.org/x/sys v0.0.0-20220804214406-8e32c043e418/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 h1:v1W7bwXHsnLLloWYTVEdvGvA7BHMeBYsPcF0GLDxIRs= +golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 6c91fae29f88..358f070d321c 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -221,6 +221,7 @@ type ConsistentSettings struct { LenChecks string `mapstructure:"len-checks"` SwitchCases string `mapstructure:"switch-cases"` SwitchDefaults string `mapstructure:"switch-defaults"` + EmptyIfaces string `mapstructure:"empty-ifaces"` LabelsRegexp string `mapstructure:"labels-regexp"` } diff --git a/pkg/golinters/consistent.go b/pkg/golinters/consistent.go index 0d5f779e36b4..8ec4a414eeae 100644 --- a/pkg/golinters/consistent.go +++ b/pkg/golinters/consistent.go @@ -49,6 +49,7 @@ func NewConsistent(settings *config.ConsistentSettings) *goanalysis.Linter { set("lenChecks", settings.LenChecks) set("switchCases", settings.SwitchCases) set("switchDefaults", settings.SwitchDefaults) + set("emptyIfaces", settings.EmptyIfaces) set("labelsRegexp", settings.LabelsRegexp) cfg[analyzer.Name] = analyzerCfg diff --git a/test/testdata/consistent.go b/test/testdata/consistent.go index e57735c40ab9..018ae85a61e2 100644 --- a/test/testdata/consistent.go +++ b/test/testdata/consistent.go @@ -1,4 +1,4 @@ -//args: -Econsistent +//golangcitest:args -Econsistent package testdata import ( // ERROR "remove parens around single import declaration" @@ -34,6 +34,8 @@ func consistent() { case 1 < 2: } + type empty interface{} // ERROR "use any instead of interface{}" + test_loop: // ERROR `change label to match regular expression: .*` for { break test_loop From 6042520215b13a2c3fcbc6310229912fc21a308b Mon Sep 17 00:00:00 2001 From: Maik Schreiber Date: Sun, 21 Aug 2022 16:16:15 +0200 Subject: [PATCH 6/7] update consistent to v0.2.2 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 4a64ae9c3859..ec4e58953ed6 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/ashanbrown/forbidigo v1.3.0 github.com/ashanbrown/makezero v1.1.1 github.com/bkielbasa/cyclop v1.2.0 - github.com/blizzy78/consistent v0.2.0 + github.com/blizzy78/consistent v0.2.2 github.com/blizzy78/varnamelen v0.8.0 github.com/bombsimon/wsl/v3 v3.3.0 github.com/breml/bidichk v0.2.3 diff --git a/go.sum b/go.sum index 469284f58a95..2505f163e7f2 100644 --- a/go.sum +++ b/go.sum @@ -75,8 +75,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bkielbasa/cyclop v1.2.0 h1:7Jmnh0yL2DjKfw28p86YTd/B4lRGcNuu12sKE35sM7A= github.com/bkielbasa/cyclop v1.2.0/go.mod h1:qOI0yy6A7dYC4Zgsa72Ppm9kONl0RoIlPbzot9mhmeI= -github.com/blizzy78/consistent v0.2.0 h1:SPUhs1liTH4C3qJVef3UwCGxsD6DwRL7AX/3Z5wdsqQ= -github.com/blizzy78/consistent v0.2.0/go.mod h1:OH+Mtm6qYm8O5tuBspt3HkRgaHkI1xrxtdm/s+w5sxI= +github.com/blizzy78/consistent v0.2.2 h1:v5tjlYRLms58lJbTagMM5omArA+PWt/UQFBJRjj5EYA= +github.com/blizzy78/consistent v0.2.2/go.mod h1:OH+Mtm6qYm8O5tuBspt3HkRgaHkI1xrxtdm/s+w5sxI= github.com/blizzy78/varnamelen v0.8.0 h1:oqSblyuQvFsW1hbBHh1zfwrKe3kcSj0rnXkKzsQ089M= github.com/blizzy78/varnamelen v0.8.0/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k= github.com/bombsimon/wsl/v3 v3.3.0 h1:Mka/+kRLoQJq7g2rggtgQsjuI/K5Efd87WX96EWFxjM= From 6968802c6a3ba7a4007bd9649a7c1ff2e140d8b0 Mon Sep 17 00:00:00 2001 From: Maik Schreiber Date: Sun, 21 Aug 2022 16:32:46 +0200 Subject: [PATCH 7/7] use "want" instead of "ERROR" --- test/testdata/consistent.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/testdata/consistent.go b/test/testdata/consistent.go index 018ae85a61e2..3d759276cdb7 100644 --- a/test/testdata/consistent.go +++ b/test/testdata/consistent.go @@ -1,42 +1,42 @@ //golangcitest:args -Econsistent package testdata -import ( // ERROR "remove parens around single import declaration" +import ( // want "remove parens around single import declaration" "strings" ) func consistent() { - _ = func(a, b int) {} // ERROR "declare the type of function arguments explicitly" + _ = func(a, b int) {} // want "declare the type of function arguments explicitly" - _ = func() (a, b int) { return 1, 2 } // ERROR "declare the type of function return values explicitly" + _ = func() (a, b int) { return 1, 2 } // want "declare the type of function return values explicitly" - _ = new(strings.Builder) // ERROR "use zero-value literal instead of calling new" + _ = new(strings.Builder) // want "use zero-value literal instead of calling new" - _ = make([]int, 0) // ERROR "use slice literal instead of calling make" + _ = make([]int, 0) // want "use slice literal instead of calling make" - _ = 0xABCDE // ERROR "use lowercase digits in hex literal" + _ = 0xABCDE // want "use lowercase digits in hex literal" x := 5 - _ = 1 < x && x < 10 // ERROR "write common term in range expression on the left" + _ = 1 < x && x < 10 // want "write common term in range expression on the left" - _ = 1 & ^2 // ERROR "use AND-NOT operator instead of AND operator with complement expression" + _ = 1 & ^2 // want "use AND-NOT operator instead of AND operator with complement expression" - _ = .5 // ERROR "add zero before decimal point in floating-point literal" + _ = .5 // want "add zero before decimal point in floating-point literal" - _ = len([]int{}) > 0 // ERROR `check if len is \(not\) 0 instead` + _ = len([]int{}) > 0 // want `check if len is \(not\) 0 instead` switch { - case 1 < 2 || 3 < 4: // ERROR "separate cases with comma instead of using logical OR" + case 1 < 2 || 3 < 4: // want "separate cases with comma instead of using logical OR" } switch { - default: // ERROR "move switch default clause to the end" + default: // want "move switch default clause to the end" case 1 < 2: } - type empty interface{} // ERROR "use any instead of interface{}" + type empty interface{} // want "use any instead of interface{}" -test_loop: // ERROR `change label to match regular expression: .*` +test_loop: // want `change label to match regular expression: .*` for { break test_loop }