From a6a9b820521c667ff5c7ab9ff3a1aa23a8b35cdc Mon Sep 17 00:00:00 2001 From: esimonov Date: Sun, 31 Jul 2022 19:10:07 +0200 Subject: [PATCH 1/3] Remove ifshort linter --- .golangci.reference.yml | 11 ----------- go.mod | 1 - go.sum | 2 -- pkg/config/linters_settings.go | 10 ---------- pkg/golinters/ifshort.go | 28 ---------------------------- pkg/lint/lintersdb/manager.go | 7 ------- test/testdata/ifshort.go | 11 ----------- 7 files changed, 70 deletions(-) delete mode 100644 pkg/golinters/ifshort.go delete mode 100644 test/testdata/ifshort.go diff --git a/.golangci.reference.yml b/.golangci.reference.yml index bff571126a43..ecf86be6919b 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -1036,15 +1036,6 @@ linters-settings: # Default: false var-require-grouping: true - ifshort: - # Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax. - # Has higher priority than max-decl-chars. - # Default: 1 - max-decl-lines: 2 - # Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax. - # Default: 30 - max-decl-chars: 40 - importas: # Do not allow unaliased imports of aliased packages. # Default: false @@ -1889,7 +1880,6 @@ linters: - gosimple - govet - grouper - - ifshort - importas - ineffassign - interfacer @@ -1990,7 +1980,6 @@ linters: - gosimple - govet - grouper - - ifshort - importas - ineffassign - interfacer diff --git a/go.mod b/go.mod index 9b94befa14cb..bfc9eaf4d091 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,6 @@ require ( github.com/charithe/durationcheck v0.0.9 github.com/daixiang0/gci v0.5.0 github.com/denis-tingaikin/go-header v0.4.3 - github.com/esimonov/ifshort v1.0.4 github.com/fatih/color v1.13.0 github.com/firefart/nonamedreturns v1.0.4 github.com/fzipp/gocyclo v0.6.0 diff --git a/go.sum b/go.sum index e5ea9aea54ce..06f7d5ebf8df 100644 --- a/go.sum +++ b/go.sum @@ -150,8 +150,6 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.0.14/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/esimonov/ifshort v1.0.4 h1:6SID4yGWfRae/M7hkVDVVyppy8q/v9OuxNdmjLQStBA= -github.com/esimonov/ifshort v1.0.4/go.mod h1:Pe8zjlRrJ80+q2CxHLfEOfTwxCZ4O+MuhcHcfgNWTk0= github.com/ettle/strcase v0.1.1 h1:htFueZyVeE1XNnMEfbqp5r67qAN/4r6ya1ysq8Q+Zcw= github.com/ettle/strcase v0.1.1/go.mod h1:hzDLsPC7/lwKyBOywSHEP89nt2pDgdy+No1NBA9o9VY= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index b0bc1ac82ffd..fa67839f0a11 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -58,10 +58,6 @@ var defaultLintersSettings = LintersSettings{ Gosec: GoSecSettings{ Concurrency: runtime.NumCPU(), }, - Ifshort: IfshortSettings{ - MaxDeclLines: 1, - MaxDeclChars: 30, - }, Lll: LllSettings{ LineLength: 120, TabWidth: 1, @@ -150,7 +146,6 @@ type LintersSettings struct { Gosimple StaticCheckSettings Govet GovetSettings Grouper GrouperSettings - Ifshort IfshortSettings ImportAs ImportAsSettings Ireturn IreturnSettings Lll LllSettings @@ -427,11 +422,6 @@ type GrouperSettings struct { VarRequireGrouping bool `mapstructure:"var-require-grouping"` } -type IfshortSettings struct { - MaxDeclLines int `mapstructure:"max-decl-lines"` - MaxDeclChars int `mapstructure:"max-decl-chars"` -} - type ImportAsSettings struct { Alias []ImportAsAlias NoUnaliased bool `mapstructure:"no-unaliased"` diff --git a/pkg/golinters/ifshort.go b/pkg/golinters/ifshort.go deleted file mode 100644 index c26f08e40365..000000000000 --- a/pkg/golinters/ifshort.go +++ /dev/null @@ -1,28 +0,0 @@ -package golinters - -import ( - "github.com/esimonov/ifshort/pkg/analyzer" - "golang.org/x/tools/go/analysis" - - "github.com/golangci/golangci-lint/pkg/config" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" -) - -func NewIfshort(settings *config.IfshortSettings) *goanalysis.Linter { - var cfg map[string]map[string]interface{} - if settings != nil { - cfg = map[string]map[string]interface{}{ - analyzer.Analyzer.Name: { - "max-decl-lines": settings.MaxDeclLines, - "max-decl-chars": settings.MaxDeclChars, - }, - } - } - - return goanalysis.NewLinter( - "ifshort", - "Checks that your code uses short syntax for if-statements whenever possible", - []*analysis.Analyzer{analyzer.Analyzer}, - cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) -} diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index 048143018dc4..04386712c1bb 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -135,7 +135,6 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { gosimpleCfg *config.StaticCheckSettings govetCfg *config.GovetSettings grouperCfg *config.GrouperSettings - ifshortCfg *config.IfshortSettings importAsCfg *config.ImportAsSettings ireturnCfg *config.IreturnSettings lllCfg *config.LllSettings @@ -206,7 +205,6 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { gosimpleCfg = &m.cfg.LintersSettings.Gosimple govetCfg = &m.cfg.LintersSettings.Govet grouperCfg = &m.cfg.LintersSettings.Grouper - ifshortCfg = &m.cfg.LintersSettings.Ifshort importAsCfg = &m.cfg.LintersSettings.ImportAs ireturnCfg = &m.cfg.LintersSettings.Ireturn lllCfg = &m.cfg.LintersSettings.Lll @@ -538,11 +536,6 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/leonklingele/grouper"), - linter.NewConfig(golinters.NewIfshort(ifshortCfg)). - WithSince("v1.36.0"). - WithPresets(linter.PresetStyle). - WithURL("https://github.com/esimonov/ifshort"), - linter.NewConfig(golinters.NewImportAs(importAsCfg)). WithSince("v1.38.0"). WithPresets(linter.PresetStyle). diff --git a/test/testdata/ifshort.go b/test/testdata/ifshort.go deleted file mode 100644 index a960b6de0644..000000000000 --- a/test/testdata/ifshort.go +++ /dev/null @@ -1,11 +0,0 @@ -//golangcitest:args -Eifshort -package testdata - -func DontUseShortSyntaxWhenPossible() { - getValue := func() interface{} { return nil } - - v := getValue() // ERROR "variable 'v' is only used in the if-statement .*" - if v != nil { - return - } -} From 364d3b82408f6d9f77038c7168bac9967c574525 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 31 Jul 2022 19:10:50 +0200 Subject: [PATCH 2/3] Revert "Remove ifshort linter" This reverts commit a6a9b820521c667ff5c7ab9ff3a1aa23a8b35cdc. --- .golangci.reference.yml | 11 +++++++++++ go.mod | 1 + go.sum | 2 ++ pkg/config/linters_settings.go | 10 ++++++++++ pkg/golinters/ifshort.go | 28 ++++++++++++++++++++++++++++ pkg/lint/lintersdb/manager.go | 7 +++++++ test/testdata/ifshort.go | 11 +++++++++++ 7 files changed, 70 insertions(+) create mode 100644 pkg/golinters/ifshort.go create mode 100644 test/testdata/ifshort.go diff --git a/.golangci.reference.yml b/.golangci.reference.yml index ecf86be6919b..bff571126a43 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -1036,6 +1036,15 @@ linters-settings: # Default: false var-require-grouping: true + ifshort: + # Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax. + # Has higher priority than max-decl-chars. + # Default: 1 + max-decl-lines: 2 + # Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax. + # Default: 30 + max-decl-chars: 40 + importas: # Do not allow unaliased imports of aliased packages. # Default: false @@ -1880,6 +1889,7 @@ linters: - gosimple - govet - grouper + - ifshort - importas - ineffassign - interfacer @@ -1980,6 +1990,7 @@ linters: - gosimple - govet - grouper + - ifshort - importas - ineffassign - interfacer diff --git a/go.mod b/go.mod index bfc9eaf4d091..9b94befa14cb 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,7 @@ require ( github.com/charithe/durationcheck v0.0.9 github.com/daixiang0/gci v0.5.0 github.com/denis-tingaikin/go-header v0.4.3 + github.com/esimonov/ifshort v1.0.4 github.com/fatih/color v1.13.0 github.com/firefart/nonamedreturns v1.0.4 github.com/fzipp/gocyclo v0.6.0 diff --git a/go.sum b/go.sum index 06f7d5ebf8df..e5ea9aea54ce 100644 --- a/go.sum +++ b/go.sum @@ -150,6 +150,8 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.0.14/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/esimonov/ifshort v1.0.4 h1:6SID4yGWfRae/M7hkVDVVyppy8q/v9OuxNdmjLQStBA= +github.com/esimonov/ifshort v1.0.4/go.mod h1:Pe8zjlRrJ80+q2CxHLfEOfTwxCZ4O+MuhcHcfgNWTk0= github.com/ettle/strcase v0.1.1 h1:htFueZyVeE1XNnMEfbqp5r67qAN/4r6ya1ysq8Q+Zcw= github.com/ettle/strcase v0.1.1/go.mod h1:hzDLsPC7/lwKyBOywSHEP89nt2pDgdy+No1NBA9o9VY= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index fa67839f0a11..b0bc1ac82ffd 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -58,6 +58,10 @@ var defaultLintersSettings = LintersSettings{ Gosec: GoSecSettings{ Concurrency: runtime.NumCPU(), }, + Ifshort: IfshortSettings{ + MaxDeclLines: 1, + MaxDeclChars: 30, + }, Lll: LllSettings{ LineLength: 120, TabWidth: 1, @@ -146,6 +150,7 @@ type LintersSettings struct { Gosimple StaticCheckSettings Govet GovetSettings Grouper GrouperSettings + Ifshort IfshortSettings ImportAs ImportAsSettings Ireturn IreturnSettings Lll LllSettings @@ -422,6 +427,11 @@ type GrouperSettings struct { VarRequireGrouping bool `mapstructure:"var-require-grouping"` } +type IfshortSettings struct { + MaxDeclLines int `mapstructure:"max-decl-lines"` + MaxDeclChars int `mapstructure:"max-decl-chars"` +} + type ImportAsSettings struct { Alias []ImportAsAlias NoUnaliased bool `mapstructure:"no-unaliased"` diff --git a/pkg/golinters/ifshort.go b/pkg/golinters/ifshort.go new file mode 100644 index 000000000000..c26f08e40365 --- /dev/null +++ b/pkg/golinters/ifshort.go @@ -0,0 +1,28 @@ +package golinters + +import ( + "github.com/esimonov/ifshort/pkg/analyzer" + "golang.org/x/tools/go/analysis" + + "github.com/golangci/golangci-lint/pkg/config" + "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" +) + +func NewIfshort(settings *config.IfshortSettings) *goanalysis.Linter { + var cfg map[string]map[string]interface{} + if settings != nil { + cfg = map[string]map[string]interface{}{ + analyzer.Analyzer.Name: { + "max-decl-lines": settings.MaxDeclLines, + "max-decl-chars": settings.MaxDeclChars, + }, + } + } + + return goanalysis.NewLinter( + "ifshort", + "Checks that your code uses short syntax for if-statements whenever possible", + []*analysis.Analyzer{analyzer.Analyzer}, + cfg, + ).WithLoadMode(goanalysis.LoadModeSyntax) +} diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index 04386712c1bb..048143018dc4 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -135,6 +135,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { gosimpleCfg *config.StaticCheckSettings govetCfg *config.GovetSettings grouperCfg *config.GrouperSettings + ifshortCfg *config.IfshortSettings importAsCfg *config.ImportAsSettings ireturnCfg *config.IreturnSettings lllCfg *config.LllSettings @@ -205,6 +206,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { gosimpleCfg = &m.cfg.LintersSettings.Gosimple govetCfg = &m.cfg.LintersSettings.Govet grouperCfg = &m.cfg.LintersSettings.Grouper + ifshortCfg = &m.cfg.LintersSettings.Ifshort importAsCfg = &m.cfg.LintersSettings.ImportAs ireturnCfg = &m.cfg.LintersSettings.Ireturn lllCfg = &m.cfg.LintersSettings.Lll @@ -536,6 +538,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/leonklingele/grouper"), + linter.NewConfig(golinters.NewIfshort(ifshortCfg)). + WithSince("v1.36.0"). + WithPresets(linter.PresetStyle). + WithURL("https://github.com/esimonov/ifshort"), + linter.NewConfig(golinters.NewImportAs(importAsCfg)). WithSince("v1.38.0"). WithPresets(linter.PresetStyle). diff --git a/test/testdata/ifshort.go b/test/testdata/ifshort.go new file mode 100644 index 000000000000..a960b6de0644 --- /dev/null +++ b/test/testdata/ifshort.go @@ -0,0 +1,11 @@ +//golangcitest:args -Eifshort +package testdata + +func DontUseShortSyntaxWhenPossible() { + getValue := func() interface{} { return nil } + + v := getValue() // ERROR "variable 'v' is only used in the if-statement .*" + if v != nil { + return + } +} From a9d944cb8d1ebb9f71992a0ce7c41f84c814854f Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 31 Jul 2022 19:23:55 +0200 Subject: [PATCH 3/3] deprecte ifshort --- pkg/lint/lintersdb/manager.go | 3 ++- test/testdata/ifshort.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index 048143018dc4..2d5174e54a82 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -541,7 +541,8 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { linter.NewConfig(golinters.NewIfshort(ifshortCfg)). WithSince("v1.36.0"). WithPresets(linter.PresetStyle). - WithURL("https://github.com/esimonov/ifshort"), + WithURL("https://github.com/esimonov/ifshort"). + Deprecated("The repository of the linter has been deprecated by the owner.", "v1.48.0", ""), linter.NewConfig(golinters.NewImportAs(importAsCfg)). WithSince("v1.38.0"). diff --git a/test/testdata/ifshort.go b/test/testdata/ifshort.go index a960b6de0644..edff1bbe870a 100644 --- a/test/testdata/ifshort.go +++ b/test/testdata/ifshort.go @@ -1,4 +1,4 @@ -//golangcitest:args -Eifshort +//golangcitest:args -Eifshort --internal-cmd-test package testdata func DontUseShortSyntaxWhenPossible() {