From 959c1626140ace0c1f598f853111476fa5cfac67 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 27 Feb 2024 23:05:55 +0100 Subject: [PATCH 1/6] chore: replace deprecated linters by noop --- pkg/lint/linter/linter.go | 7 +++++++ pkg/lint/lintersdb/builder_linter.go | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pkg/lint/linter/linter.go b/pkg/lint/linter/linter.go index e086bbe5fcc7..45f62bc3d8cb 100644 --- a/pkg/lint/linter/linter.go +++ b/pkg/lint/linter/linter.go @@ -26,6 +26,13 @@ func NewNoop(l Linter, reason string) Noop { } } +func NewNoopDeprecated(name string) Noop { + return Noop{ + name: name, + desc: "Deprecated", + } +} + func (n Noop) Run(_ context.Context, lintCtx *Context) ([]result.Issue, error) { if n.reason != "" { lintCtx.Log.Warnf("%s: %s", n.name, n.reason) diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index 9452a2b4ef3f..eba79f3d0e5c 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -77,7 +77,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithPresets(linter.PresetFormatting, linter.PresetStyle). WithURL("https://gitlab.com/bosi/decorder"), - linter.NewConfig(golinters.NewDeadcode()). + linter.NewConfig(linter.NewNoopDeprecated("deadcode")). WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetUnused). @@ -148,12 +148,12 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithLoadForGoAnalysis(). WithURL("https://github.com/nishanths/exhaustive"), - linter.NewConfig(golinters.NewExhaustiveStruct(&cfg.LintersSettings.ExhaustiveStruct)). + linter.NewConfig(linter.NewNoopDeprecated("exhaustivestruct")). WithSince("v1.32.0"). WithPresets(linter.PresetStyle, linter.PresetTest). WithLoadForGoAnalysis(). WithURL("https://github.com/mbilski/exhaustivestruct"). - Deprecated("The owner seems to have abandoned the linter.", "v1.46.0", "exhaustruct"), + Deprecated("The repository of the linter has been deprecated by the owner.", "v1.46.0", "exhaustruct"), linter.NewConfig(golinters.NewExhaustruct(&cfg.LintersSettings.Exhaustruct)). WithSince("v1.46.0"). @@ -280,7 +280,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithAutoFix(). WithURL("https://pkg.go.dev/golang.org/x/tools/cmd/goimports"), - linter.NewConfig(golinters.NewGolint(&cfg.LintersSettings.Golint)). + linter.NewConfig(linter.NewNoopDeprecated("golint")). WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetStyle). @@ -341,7 +341,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/leonklingele/grouper"), - linter.NewConfig(golinters.NewIfshort(&cfg.LintersSettings.Ifshort)). + linter.NewConfig(linter.NewNoopDeprecated("ifshort")). WithSince("v1.36.0"). WithPresets(linter.PresetStyle). WithURL("https://github.com/esimonov/ifshort"). @@ -369,7 +369,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/sashamelentyev/interfacebloat"), - linter.NewConfig(golinters.NewInterfacer()). + linter.NewConfig(linter.NewNoopDeprecated("interfacer")). WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetStyle). @@ -409,7 +409,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithLoadForGoAnalysis(). WithURL("https://github.com/ashanbrown/makezero"), - linter.NewConfig(golinters.NewMaligned(&cfg.LintersSettings.Maligned)). + linter.NewConfig(linter.NewNoopDeprecated("maligned")). WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetPerformance). @@ -473,7 +473,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/firefart/nonamedreturns"), - linter.NewConfig(golinters.NewNoSnakeCase()). + linter.NewConfig(linter.NewNoopDeprecated("nosnakecase")). WithSince("v1.47.0"). WithPresets(linter.PresetStyle). WithURL("https://github.com/sivchari/nosnakecase"). @@ -542,7 +542,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithPresets(linter.PresetStyle, linter.PresetFormatting). WithURL("https://github.com/go-simpler/sloglint"), - linter.NewConfig(golinters.NewScopelint()). + linter.NewConfig(linter.NewNoopDeprecated("scopelint")). WithSince("v1.12.0"). WithPresets(linter.PresetBugs). WithURL("https://github.com/kyoh86/scopelint"). @@ -568,7 +568,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithAlternativeNames(megacheckName). WithURL("https://staticcheck.io/"), - linter.NewConfig(golinters.NewStructcheck(&cfg.LintersSettings.Structcheck)). + linter.NewConfig(linter.NewNoopDeprecated("structcheck")). WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetUnused). @@ -661,7 +661,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/sashamelentyev/usestdlibvars"), - linter.NewConfig(golinters.NewVarcheck(&cfg.LintersSettings.Varcheck)). + linter.NewConfig(linter.NewNoopDeprecated("varcheck")). WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetUnused). From 5b0380c4f0d40b4024e39bd38dab16d2e96e3747 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 27 Feb 2024 23:10:56 +0100 Subject: [PATCH 2/6] chore: remove code related to deprecated linters --- go.mod | 9 - go.sum | 19 --- pkg/golinters/deadcode.go | 61 ------- pkg/golinters/exhaustivestruct.go | 31 ---- pkg/golinters/golint.go | 84 --------- pkg/golinters/ifshort.go | 30 ---- pkg/golinters/interfacer.go | 82 --------- pkg/golinters/maligned.go | 74 -------- pkg/golinters/nosnakecase.go | 19 --- pkg/golinters/scopelint.go | 190 --------------------- pkg/golinters/structcheck.go | 71 -------- pkg/golinters/unconvert.go | 1 - pkg/golinters/util.go | 8 - pkg/golinters/varcheck.go | 72 -------- test/testdata/configs/exhaustivestruct.yml | 5 - test/testdata/deadcode.go | 21 --- test/testdata/exhaustivestruct.go | 46 ----- test/testdata/exhaustivestruct_custom.go | 129 -------------- test/testdata/golint.go | 22 --- test/testdata/ifshort.go | 13 -- test/testdata/interfacer.go | 8 - test/testdata/maligned.go | 8 - test/testdata/nosnakecase.go | 149 ---------------- test/testdata/scopelint.go | 17 -- test/testdata/structcheck.go | 6 - test/testdata/varcheck.go | 4 - 26 files changed, 1179 deletions(-) delete mode 100644 pkg/golinters/deadcode.go delete mode 100644 pkg/golinters/exhaustivestruct.go delete mode 100644 pkg/golinters/golint.go delete mode 100644 pkg/golinters/ifshort.go delete mode 100644 pkg/golinters/interfacer.go delete mode 100644 pkg/golinters/maligned.go delete mode 100644 pkg/golinters/nosnakecase.go delete mode 100644 pkg/golinters/scopelint.go delete mode 100644 pkg/golinters/structcheck.go delete mode 100644 pkg/golinters/varcheck.go delete mode 100644 test/testdata/configs/exhaustivestruct.yml delete mode 100644 test/testdata/deadcode.go delete mode 100644 test/testdata/exhaustivestruct.go delete mode 100644 test/testdata/exhaustivestruct_custom.go delete mode 100644 test/testdata/golint.go delete mode 100644 test/testdata/ifshort.go delete mode 100644 test/testdata/interfacer.go delete mode 100644 test/testdata/maligned.go delete mode 100644 test/testdata/nosnakecase.go delete mode 100644 test/testdata/scopelint.go delete mode 100644 test/testdata/structcheck.go delete mode 100644 test/testdata/varcheck.go diff --git a/go.mod b/go.mod index c9d3f3ba08c3..72641fea407c 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,6 @@ require ( github.com/curioswitch/go-reassign v0.2.0 github.com/daixiang0/gci v0.13.0 github.com/denis-tingaikin/go-header v0.5.0 - github.com/esimonov/ifshort v1.0.4 github.com/fatih/color v1.16.0 github.com/firefart/nonamedreturns v1.0.4 github.com/fzipp/gocyclo v0.6.0 @@ -42,12 +41,8 @@ require ( github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 github.com/go-xmlfmt/xmlfmt v1.1.2 github.com/gofrs/flock v0.8.1 - github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a - github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe github.com/golangci/gofmt v0.0.0-20231018234816-f50ced29576e - github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0 - github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca github.com/golangci/misspell v0.4.1 github.com/golangci/revgrep v0.5.2 github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 @@ -76,7 +71,6 @@ require ( github.com/maratori/testpackage v1.1.1 github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26 github.com/mattn/go-colorable v0.1.13 - github.com/mbilski/exhaustivestruct v1.2.0 github.com/mgechev/revive v1.3.7 github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-ps v1.0.0 @@ -97,7 +91,6 @@ require ( github.com/shirou/gopsutil/v3 v3.24.2 github.com/sirupsen/logrus v1.9.3 github.com/sivchari/containedctx v1.0.3 - github.com/sivchari/nosnakecase v1.7.0 github.com/sivchari/tenv v1.7.1 github.com/sonatard/noctx v0.0.2 github.com/sourcegraph/go-diff v0.7.0 @@ -130,7 +123,6 @@ require ( gopkg.in/yaml.v3 v3.0.1 honnef.co/go/tools v0.4.7 mvdan.cc/gofumpt v0.6.0 - mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed mvdan.cc/unparam v0.0.0-20240104100049-c549a3470d14 ) @@ -201,5 +193,4 @@ require ( google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect ) diff --git a/go.sum b/go.sum index e099cf933ddc..451a6ca55905 100644 --- a/go.sum +++ b/go.sum @@ -133,8 +133,6 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= 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.2.0 h1:fGNiVF21fHXpX1niBgk0aROov1LagYsOwV/xqKDKR/Q= github.com/ettle/strcase v0.2.0/go.mod h1:DajmHElDSaX76ITe3/VHVyMin4LWSJN5Z909Wp+ED1A= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= @@ -227,18 +225,10 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 h1:23T5iq8rbUYlhpt5DB4XJkc6BU31uODLD1o1gKvZmD0= -github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2/go.mod h1:k9Qvh+8juN+UKMCS/3jFtGICgW8O96FVaZsaxdzDkR4= github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a h1:w8hkcTqaFpzKqonE9uMCefW1WDie15eSP/4MssdenaM= github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a/go.mod h1:ryS0uhF+x9jgbj/N71xsEqODy9BN81/GonCZiOzirOk= -github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe h1:6RGUuS7EGotKx6J5HIP8ZtyMdiDscjMLfRBSPuzVVeo= -github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe/go.mod h1:gjqyPShc/m8pEMpk0a3SeagVb0kaqvhscv+i9jI5ZhQ= github.com/golangci/gofmt v0.0.0-20231018234816-f50ced29576e h1:ULcKCDV1LOZPFxGZaA6TlQbiM3J2GCPnkx/bGF6sX/g= github.com/golangci/gofmt v0.0.0-20231018234816-f50ced29576e/go.mod h1:Pm5KhLPA8gSnQwrQ6ukebRcapGb/BG9iUkdaiCcGHJM= -github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0 h1:MfyDlzVjl1hoaPzPD4Gpb/QgoRfSBR0jdhwGyAWwMSA= -github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0/go.mod h1:66R6K6P6VWk9I95jvqGxkqJxVWGFy9XlDwLwVz1RCFg= -github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca h1:kNY3/svz5T29MYHubXix4aDDuE3RWHkPvopM/EDv/MA= -github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca/go.mod h1:tvlJhZqDe4LMs4ZHD0oMUlt9G2LWuDGoisJTBzLMV9o= github.com/golangci/misspell v0.4.1 h1:+y73iSicVy2PqyX7kmUefHusENlrP9YwuHZHPLGQj/g= github.com/golangci/misspell v0.4.1/go.mod h1:9mAN1quEo3DlpbaIKKyEvRxK1pwqR9s/Sea1bJCtlNI= github.com/golangci/revgrep v0.5.2 h1:EndcWoRhcnfj2NHQ+28hyuXpLMF+dQmCN+YaeeIl4FU= @@ -379,8 +369,6 @@ github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/Qd github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mbilski/exhaustivestruct v1.2.0 h1:wCBmUnSYufAHO6J4AVWY6ff+oxWxsVFrwgOdMUQePUo= -github.com/mbilski/exhaustivestruct v1.2.0/go.mod h1:OeTBVxQWoEmB2J2JCHmXWPJ0aksxSUOUy+nvtVEfzXc= github.com/mgechev/revive v1.3.7 h1:502QY0vQGe9KtYJ9FpxMz9rL+Fc/P13CI5POL4uHCcE= github.com/mgechev/revive v1.3.7/go.mod h1:RJ16jUbF0OWC3co/+XTxmFNgEpUPwnnA0BRllX2aDNA= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -500,8 +488,6 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/sivchari/containedctx v1.0.3 h1:x+etemjbsh2fB5ewm5FeLNi5bUjK0V8n0RB+Wwfd0XE= github.com/sivchari/containedctx v1.0.3/go.mod h1:c1RDvCbnJLtH4lLcYD/GqwiBSSf4F5Qk0xld2rBqzJ4= -github.com/sivchari/nosnakecase v1.7.0 h1:7QkpWIRMe8x25gckkFd2A5Pi6Ymo0qgr4JrhGt95do8= -github.com/sivchari/nosnakecase v1.7.0/go.mod h1:CwDzrzPea40/GB6uynrNLiorAlgFRvRbFSgJx2Gs+QY= github.com/sivchari/tenv v1.7.1 h1:PSpuD4bu6fSmtWMxSGWcvqUUgIn7k3yOJhOIzVWn8Ak= github.com/sivchari/tenv v1.7.1/go.mod h1:64yStXKSOxDfX47NlhVwND4dHwfZDdbp2Lyl018Icvg= github.com/sonatard/noctx v0.0.2 h1:L7Dz4De2zDQhW8S0t+KUjY0MAQJd6SgVwhzNIc4ok00= @@ -862,7 +848,6 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200820010801-b793a1359eac/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20201001104356-43ebab892c4c/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/tools v0.0.0-20201023174141-c8cfbd0f21e6/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1-0.20210205202024-ef80cdb6ec6d/go.mod h1:9bzcO0MWcOuT0tm1iBGzDVPshzfwoVvREIui8C+MHqU= @@ -989,10 +974,6 @@ honnef.co/go/tools v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs= honnef.co/go/tools v0.4.7/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0= mvdan.cc/gofumpt v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo= mvdan.cc/gofumpt v0.6.0/go.mod h1:4L0wf+kgIPZtcCWXynNS2e6bhmj73umwnuXSZarixzA= -mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed h1:WX1yoOaKQfddO/mLzdV4wptyWgoH/6hwLs7QHTixo0I= -mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc= -mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b h1:DxJ5nJdkhDlLok9K6qO+5290kphDJbHOQO1DFFFTeBo= -mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4= mvdan.cc/unparam v0.0.0-20240104100049-c549a3470d14 h1:zCr3iRRgdk5eIikZNDphGcM6KGVTx3Yu+/Uu9Es254w= mvdan.cc/unparam v0.0.0-20240104100049-c549a3470d14/go.mod h1:ZzZjEpJDOmx8TdVU6umamY3Xy0UAQUI2DHbf05USVbI= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/pkg/golinters/deadcode.go b/pkg/golinters/deadcode.go deleted file mode 100644 index 4f563c381339..000000000000 --- a/pkg/golinters/deadcode.go +++ /dev/null @@ -1,61 +0,0 @@ -package golinters - -import ( - "fmt" - "sync" - - deadcodeAPI "github.com/golangci/go-misc/deadcode" - "golang.org/x/tools/go/analysis" - - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" - "github.com/golangci/golangci-lint/pkg/lint/linter" - "github.com/golangci/golangci-lint/pkg/result" -) - -const deadcodeName = "deadcode" - -func NewDeadcode() *goanalysis.Linter { - var mu sync.Mutex - var resIssues []goanalysis.Issue - - analyzer := &analysis.Analyzer{ - Name: deadcodeName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - prog := goanalysis.MakeFakeLoaderProgram(pass) - - issues, err := deadcodeAPI.Run(prog) - if err != nil { - return nil, err - } - - res := make([]goanalysis.Issue, 0, len(issues)) - for _, i := range issues { - res = append(res, goanalysis.NewIssue(&result.Issue{ - Pos: i.Pos, - Text: fmt.Sprintf("%s is unused", formatCode(i.UnusedIdentName, nil)), - FromLinter: deadcodeName, - }, pass)) - } - - if len(issues) == 0 { - return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, res...) - mu.Unlock() - - return nil, nil - }, - } - - return goanalysis.NewLinter( - deadcodeName, - "Finds unused code", - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeTypesInfo) -} diff --git a/pkg/golinters/exhaustivestruct.go b/pkg/golinters/exhaustivestruct.go deleted file mode 100644 index 9bc9bbfb0b0e..000000000000 --- a/pkg/golinters/exhaustivestruct.go +++ /dev/null @@ -1,31 +0,0 @@ -package golinters - -import ( - "strings" - - "github.com/mbilski/exhaustivestruct/pkg/analyzer" - "golang.org/x/tools/go/analysis" - - "github.com/golangci/golangci-lint/pkg/config" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" -) - -func NewExhaustiveStruct(settings *config.ExhaustiveStructSettings) *goanalysis.Linter { - a := analyzer.Analyzer - - var cfg map[string]map[string]any - if settings != nil { - cfg = map[string]map[string]any{ - a.Name: { - "struct_patterns": strings.Join(settings.StructPatterns, ","), - }, - } - } - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) -} diff --git a/pkg/golinters/golint.go b/pkg/golinters/golint.go deleted file mode 100644 index 22ca590481ab..000000000000 --- a/pkg/golinters/golint.go +++ /dev/null @@ -1,84 +0,0 @@ -package golinters - -import ( - "fmt" - "sync" - - lintAPI "github.com/golangci/lint-1" - "golang.org/x/tools/go/analysis" - - "github.com/golangci/golangci-lint/pkg/config" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" - "github.com/golangci/golangci-lint/pkg/lint/linter" - "github.com/golangci/golangci-lint/pkg/result" -) - -const golintName = "golint" - -//nolint:dupl -func NewGolint(settings *config.GoLintSettings) *goanalysis.Linter { - var mu sync.Mutex - var resIssues []goanalysis.Issue - - analyzer := &analysis.Analyzer{ - Name: golintName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - issues, err := runGoLint(pass, settings) - if err != nil { - return nil, err - } - - if len(issues) == 0 { - return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() - - return nil, nil - }, - } - - return goanalysis.NewLinter( - golintName, - "Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes", - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeTypesInfo) -} - -func runGoLint(pass *analysis.Pass, settings *config.GoLintSettings) ([]goanalysis.Issue, error) { - l := new(lintAPI.Linter) - - ps, err := l.LintPkg(pass.Files, pass.Fset, pass.Pkg, pass.TypesInfo) - if err != nil { - return nil, fmt.Errorf("can't lint %d files: %w", len(pass.Files), err) - } - - if len(ps) == 0 { - return nil, nil - } - - lintIssues := make([]*result.Issue, 0, len(ps)) // This is worst case - for idx := range ps { - if ps[idx].Confidence >= settings.MinConfidence { - lintIssues = append(lintIssues, &result.Issue{ - Pos: ps[idx].Position, - Text: ps[idx].Text, - FromLinter: golintName, - }) - // TODO: use p.Link and p.Category - } - } - - issues := make([]goanalysis.Issue, 0, len(lintIssues)) - for _, issue := range lintIssues { - issues = append(issues, goanalysis.NewIssue(issue, pass)) - } - - return issues, nil -} diff --git a/pkg/golinters/ifshort.go b/pkg/golinters/ifshort.go deleted file mode 100644 index 50e2c172ef0b..000000000000 --- a/pkg/golinters/ifshort.go +++ /dev/null @@ -1,30 +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]any - if settings != nil { - cfg = map[string]map[string]any{ - analyzer.Analyzer.Name: { - "max-decl-lines": settings.MaxDeclLines, - "max-decl-chars": settings.MaxDeclChars, - }, - } - } - - a := analyzer.Analyzer - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) -} diff --git a/pkg/golinters/interfacer.go b/pkg/golinters/interfacer.go deleted file mode 100644 index 71bdfddbe815..000000000000 --- a/pkg/golinters/interfacer.go +++ /dev/null @@ -1,82 +0,0 @@ -package golinters - -import ( - "sync" - - "golang.org/x/tools/go/analysis" - "golang.org/x/tools/go/analysis/passes/buildssa" - "mvdan.cc/interfacer/check" - - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" - "github.com/golangci/golangci-lint/pkg/lint/linter" - "github.com/golangci/golangci-lint/pkg/result" -) - -const interfacerName = "interfacer" - -func NewInterfacer() *goanalysis.Linter { - var mu sync.Mutex - var resIssues []goanalysis.Issue - - analyzer := &analysis.Analyzer{ - Name: interfacerName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Requires: []*analysis.Analyzer{buildssa.Analyzer}, - Run: func(pass *analysis.Pass) (any, error) { - issues, err := runInterfacer(pass) - if err != nil { - return nil, err - } - - if len(issues) == 0 { - return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() - - return nil, nil - }, - } - - return goanalysis.NewLinter( - interfacerName, - "Linter that suggests narrower interface types", - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeTypesInfo) -} - -func runInterfacer(pass *analysis.Pass) ([]goanalysis.Issue, error) { - c := &check.Checker{} - - prog := goanalysis.MakeFakeLoaderProgram(pass) - c.Program(prog) - - ssa := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA) - ssaPkg := ssa.Pkg - c.ProgramSSA(ssaPkg.Prog) - - lintIssues, err := c.Check() - if err != nil { - return nil, err - } - if len(lintIssues) == 0 { - return nil, nil - } - - issues := make([]goanalysis.Issue, 0, len(lintIssues)) - for _, i := range lintIssues { - pos := pass.Fset.Position(i.Pos()) - issues = append(issues, goanalysis.NewIssue(&result.Issue{ - Pos: pos, - Text: i.Message(), - FromLinter: interfacerName, - }, pass)) - } - - return issues, nil -} diff --git a/pkg/golinters/maligned.go b/pkg/golinters/maligned.go deleted file mode 100644 index 0455be76aa99..000000000000 --- a/pkg/golinters/maligned.go +++ /dev/null @@ -1,74 +0,0 @@ -package golinters - -import ( - "fmt" - "sync" - - malignedAPI "github.com/golangci/maligned" - "golang.org/x/tools/go/analysis" - - "github.com/golangci/golangci-lint/pkg/config" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" - "github.com/golangci/golangci-lint/pkg/lint/linter" - "github.com/golangci/golangci-lint/pkg/result" -) - -const malignedName = "maligned" - -//nolint:dupl -func NewMaligned(settings *config.MalignedSettings) *goanalysis.Linter { - var mu sync.Mutex - var res []goanalysis.Issue - - analyzer := &analysis.Analyzer{ - Name: malignedName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - issues := runMaligned(pass, settings) - - if len(issues) == 0 { - return nil, nil - } - - mu.Lock() - res = append(res, issues...) - mu.Unlock() - - return nil, nil - }, - } - - return goanalysis.NewLinter( - malignedName, - "Tool to detect Go structs that would take less memory if their fields were sorted", - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return res - }).WithLoadMode(goanalysis.LoadModeTypesInfo) -} - -func runMaligned(pass *analysis.Pass, settings *config.MalignedSettings) []goanalysis.Issue { - prog := goanalysis.MakeFakeLoaderProgram(pass) - - malignedIssues := malignedAPI.Run(prog) - if len(malignedIssues) == 0 { - return nil - } - - issues := make([]goanalysis.Issue, 0, len(malignedIssues)) - for _, i := range malignedIssues { - text := fmt.Sprintf("struct of size %d bytes could be of size %d bytes", i.OldSize, i.NewSize) - if settings.SuggestNewOrder { - text += fmt.Sprintf(":\n%s", formatCodeBlock(i.NewStructDef, nil)) - } - - issues = append(issues, goanalysis.NewIssue(&result.Issue{ - Pos: i.Pos, - Text: text, - FromLinter: malignedName, - }, pass)) - } - - return issues -} diff --git a/pkg/golinters/nosnakecase.go b/pkg/golinters/nosnakecase.go deleted file mode 100644 index 26d5d6d4c84f..000000000000 --- a/pkg/golinters/nosnakecase.go +++ /dev/null @@ -1,19 +0,0 @@ -package golinters - -import ( - "github.com/sivchari/nosnakecase" - "golang.org/x/tools/go/analysis" - - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" -) - -func NewNoSnakeCase() *goanalysis.Linter { - a := nosnakecase.Analyzer - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) -} diff --git a/pkg/golinters/scopelint.go b/pkg/golinters/scopelint.go deleted file mode 100644 index e6ef15ede049..000000000000 --- a/pkg/golinters/scopelint.go +++ /dev/null @@ -1,190 +0,0 @@ -package golinters - -import ( - "fmt" - "go/ast" - "go/token" - "sync" - - "golang.org/x/tools/go/analysis" - - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" - "github.com/golangci/golangci-lint/pkg/lint/linter" - "github.com/golangci/golangci-lint/pkg/result" -) - -const scopelintName = "scopelint" - -//nolint:dupl -func NewScopelint() *goanalysis.Linter { - var mu sync.Mutex - var resIssues []goanalysis.Issue - - analyzer := &analysis.Analyzer{ - Name: scopelintName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - issues := runScopeLint(pass) - - if len(issues) == 0 { - return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() - - return nil, nil - }, - } - - return goanalysis.NewLinter( - scopelintName, - "Scopelint checks for unpinned variables in go programs", - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeSyntax) -} - -func runScopeLint(pass *analysis.Pass) []goanalysis.Issue { - var lintIssues []result.Issue - - for _, file := range pass.Files { - n := Node{ - fset: pass.Fset, - DangerObjects: map[*ast.Object]int{}, - UnsafeObjects: map[*ast.Object]int{}, - SkipFuncs: map[*ast.FuncLit]int{}, - issues: &lintIssues, - } - ast.Walk(&n, file) - } - - var issues []goanalysis.Issue - for i := range lintIssues { - issues = append(issues, goanalysis.NewIssue(&lintIssues[i], pass)) - } - - return issues -} - -// The code below is copy-pasted from https://github.com/kyoh86/scopelint 92cbe2cc9276abda0e309f52cc9e309d407f174e - -// Node represents a Node being linted. -type Node struct { - fset *token.FileSet - DangerObjects map[*ast.Object]int - UnsafeObjects map[*ast.Object]int - SkipFuncs map[*ast.FuncLit]int - issues *[]result.Issue -} - -// Visit method is invoked for each node encountered by Walk. -// If the result visitor w is not nil, Walk visits each of the children -// of node with the visitor w, followed by a call of w.Visit(nil). -// -//nolint:gocyclo,gocritic -func (f *Node) Visit(node ast.Node) ast.Visitor { - switch typedNode := node.(type) { - case *ast.ForStmt: - switch init := typedNode.Init.(type) { - case *ast.AssignStmt: - for _, lh := range init.Lhs { - switch tlh := lh.(type) { - case *ast.Ident: - f.UnsafeObjects[tlh.Obj] = 0 - } - } - } - - case *ast.RangeStmt: - // Memory variables declared in range statement - switch k := typedNode.Key.(type) { - case *ast.Ident: - f.UnsafeObjects[k.Obj] = 0 - } - switch v := typedNode.Value.(type) { - case *ast.Ident: - f.UnsafeObjects[v.Obj] = 0 - } - - case *ast.UnaryExpr: - if typedNode.Op == token.AND { - switch ident := typedNode.X.(type) { - case *ast.Ident: - if _, unsafe := f.UnsafeObjects[ident.Obj]; unsafe { - f.errorf(ident, "Using a reference for the variable on range scope %s", formatCode(ident.Name, nil)) - } - } - } - - case *ast.Ident: - if _, obj := f.DangerObjects[typedNode.Obj]; obj { - // It is the naked variable in scope of range statement. - f.errorf(node, "Using the variable on range scope %s in function literal", formatCode(typedNode.Name, nil)) - break - } - - case *ast.CallExpr: - // Ignore func literals that'll be called immediately. - switch funcLit := typedNode.Fun.(type) { - case *ast.FuncLit: - f.SkipFuncs[funcLit] = 0 - } - - case *ast.FuncLit: - if _, skip := f.SkipFuncs[typedNode]; !skip { - dangers := map[*ast.Object]int{} - for d := range f.DangerObjects { - dangers[d] = 0 - } - for u := range f.UnsafeObjects { - dangers[u] = 0 - f.UnsafeObjects[u]++ - } - return &Node{ - fset: f.fset, - DangerObjects: dangers, - UnsafeObjects: f.UnsafeObjects, - SkipFuncs: f.SkipFuncs, - issues: f.issues, - } - } - - case *ast.ReturnStmt: - unsafe := map[*ast.Object]int{} - for u := range f.UnsafeObjects { - if f.UnsafeObjects[u] == 0 { - continue - } - unsafe[u] = f.UnsafeObjects[u] - } - return &Node{ - fset: f.fset, - DangerObjects: f.DangerObjects, - UnsafeObjects: unsafe, - SkipFuncs: f.SkipFuncs, - issues: f.issues, - } - } - return f -} - -// The variadic arguments may start with link and category types, -// and must end with a format string and any arguments. -// -//nolint:interfacer -func (f *Node) errorf(n ast.Node, format string, args ...any) { - pos := f.fset.Position(n.Pos()) - f.errorAtf(pos, format, args...) -} - -func (f *Node) errorAtf(pos token.Position, format string, args ...any) { - *f.issues = append(*f.issues, result.Issue{ - Pos: pos, - Text: fmt.Sprintf(format, args...), - FromLinter: scopelintName, - }) -} diff --git a/pkg/golinters/structcheck.go b/pkg/golinters/structcheck.go deleted file mode 100644 index f3df0c2f3552..000000000000 --- a/pkg/golinters/structcheck.go +++ /dev/null @@ -1,71 +0,0 @@ -package golinters - -import ( - "fmt" - "sync" - - structcheckAPI "github.com/golangci/check/cmd/structcheck" - "golang.org/x/tools/go/analysis" - - "github.com/golangci/golangci-lint/pkg/config" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" - "github.com/golangci/golangci-lint/pkg/lint/linter" - "github.com/golangci/golangci-lint/pkg/result" -) - -const structcheckName = "structcheck" - -//nolint:dupl -func NewStructcheck(settings *config.StructCheckSettings) *goanalysis.Linter { - var mu sync.Mutex - var resIssues []goanalysis.Issue - - analyzer := &analysis.Analyzer{ - Name: structcheckName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - issues := runStructCheck(pass, settings) - - if len(issues) == 0 { - return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() - - return nil, nil - }, - } - - return goanalysis.NewLinter( - structcheckName, - "Finds unused struct fields", - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeTypesInfo) -} - -//nolint:dupl -func runStructCheck(pass *analysis.Pass, settings *config.StructCheckSettings) []goanalysis.Issue { - prog := goanalysis.MakeFakeLoaderProgram(pass) - - lintIssues := structcheckAPI.Run(prog, settings.CheckExportedFields) - if len(lintIssues) == 0 { - return nil - } - - issues := make([]goanalysis.Issue, 0, len(lintIssues)) - - for _, i := range lintIssues { - issues = append(issues, goanalysis.NewIssue(&result.Issue{ - Pos: i.Pos, - Text: fmt.Sprintf("%s is unused", formatCode(i.FieldName, nil)), - FromLinter: structcheckName, - }, pass)) - } - - return issues -} diff --git a/pkg/golinters/unconvert.go b/pkg/golinters/unconvert.go index aad858dfd696..1e44f9fa5834 100644 --- a/pkg/golinters/unconvert.go +++ b/pkg/golinters/unconvert.go @@ -13,7 +13,6 @@ import ( const unconvertName = "unconvert" -//nolint:dupl func NewUnconvert() *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/util.go b/pkg/golinters/util.go index 1044567a951b..932cbfcf78f6 100644 --- a/pkg/golinters/util.go +++ b/pkg/golinters/util.go @@ -18,14 +18,6 @@ func formatCode(code string, _ *config.Config) string { return fmt.Sprintf("`%s`", code) } -func formatCodeBlock(code string, _ *config.Config) string { - if strings.Contains(code, "`") { - return code // TODO: properly escape or remove - } - - return fmt.Sprintf("```\n%s\n```", code) -} - func getFileNames(pass *analysis.Pass) []string { var fileNames []string for _, f := range pass.Files { diff --git a/pkg/golinters/varcheck.go b/pkg/golinters/varcheck.go deleted file mode 100644 index ea735672f62f..000000000000 --- a/pkg/golinters/varcheck.go +++ /dev/null @@ -1,72 +0,0 @@ -package golinters - -import ( - "fmt" - "sync" - - varcheckAPI "github.com/golangci/check/cmd/varcheck" - "golang.org/x/tools/go/analysis" - - "github.com/golangci/golangci-lint/pkg/config" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" - "github.com/golangci/golangci-lint/pkg/lint/linter" - "github.com/golangci/golangci-lint/pkg/result" -) - -const varcheckName = "varcheck" - -func NewVarcheck(settings *config.VarCheckSettings) *goanalysis.Linter { - var mu sync.Mutex - var resIssues []goanalysis.Issue - - analyzer := &analysis.Analyzer{ - Name: varcheckName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: goanalysis.DummyRun, - } - - return goanalysis.NewLinter( - varcheckName, - "Finds unused global variables and constants", - []*analysis.Analyzer{analyzer}, - nil, - ).WithContextSetter(func(_ *linter.Context) { - analyzer.Run = func(pass *analysis.Pass) (any, error) { - issues := runVarCheck(pass, settings) - - if len(issues) == 0 { - return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() - - return nil, nil - } - }).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeTypesInfo) -} - -//nolint:dupl -func runVarCheck(pass *analysis.Pass, settings *config.VarCheckSettings) []goanalysis.Issue { - prog := goanalysis.MakeFakeLoaderProgram(pass) - - lintIssues := varcheckAPI.Run(prog, settings.CheckExportedFields) - if len(lintIssues) == 0 { - return nil - } - - issues := make([]goanalysis.Issue, 0, len(lintIssues)) - - for _, i := range lintIssues { - issues = append(issues, goanalysis.NewIssue(&result.Issue{ - Pos: i.Pos, - Text: fmt.Sprintf("%s is unused", formatCode(i.VarName, nil)), - FromLinter: varcheckName, - }, pass)) - } - - return issues -} diff --git a/test/testdata/configs/exhaustivestruct.yml b/test/testdata/configs/exhaustivestruct.yml deleted file mode 100644 index 21d69c55dd76..000000000000 --- a/test/testdata/configs/exhaustivestruct.yml +++ /dev/null @@ -1,5 +0,0 @@ -linters-settings: - exhaustivestruct: - struct-patterns: - - '*.ExhaustiveStructCustom' - - '*.ExhaustiveStructCustom2' diff --git a/test/testdata/deadcode.go b/test/testdata/deadcode.go deleted file mode 100644 index 670047a548f0..000000000000 --- a/test/testdata/deadcode.go +++ /dev/null @@ -1,21 +0,0 @@ -//golangcitest:args -Edeadcode --internal-cmd-test -package testdata - -var y int - -var unused int // want "`unused` is unused" - -func f(x int) { -} - -func g(x int) { // want "`g` is unused" -} - -func H(x int) { -} - -func init() { - f(y) -} - -var _ int diff --git a/test/testdata/exhaustivestruct.go b/test/testdata/exhaustivestruct.go deleted file mode 100644 index 50476cebaffa..000000000000 --- a/test/testdata/exhaustivestruct.go +++ /dev/null @@ -1,46 +0,0 @@ -//golangcitest:args -Eexhaustivestruct --internal-cmd-test -package testdata - -import "time" - -type ExhaustiveStruct struct { - A string - B int - c bool // private field inside the same package are not ignored - D float64 - E time.Time -} - -func exhaustiveStruct() { - // pass - _ = ExhaustiveStruct{ - A: "a", - B: 0, - c: false, - D: 1.0, - E: time.Now(), - } - - // failPrivate - _ = ExhaustiveStruct{ // want "c is missing in ExhaustiveStruct" - A: "a", - B: 0, - D: 1.0, - E: time.Now(), - } - - // fail - _ = ExhaustiveStruct{ // want "B is missing in ExhaustiveStruct" - A: "a", - c: false, - D: 1.0, - E: time.Now(), - } - - // failMultiple - _ = ExhaustiveStruct{ // want "B, D are missing in ExhaustiveStruct" - A: "a", - c: false, - E: time.Now(), - } -} diff --git a/test/testdata/exhaustivestruct_custom.go b/test/testdata/exhaustivestruct_custom.go deleted file mode 100644 index 08fde43f8e88..000000000000 --- a/test/testdata/exhaustivestruct_custom.go +++ /dev/null @@ -1,129 +0,0 @@ -//golangcitest:args -Eexhaustivestruct --internal-cmd-test -//golangcitest:config_path testdata/configs/exhaustivestruct.yml -package testdata - -import "time" - -type ExhaustiveStructCustom struct { - A string - B int - c bool // private field inside the same package are not ignored - D float64 - E time.Time -} - -func exhaustiveStructCustom() { - // pass - _ = ExhaustiveStructCustom{ - A: "a", - B: 0, - c: false, - D: 1.0, - E: time.Now(), - } - - // fail - _ = ExhaustiveStructCustom{ // want "B is missing in ExhaustiveStructCustom" - A: "a", - c: false, - D: 1.0, - E: time.Now(), - } - - // failMultiple - _ = ExhaustiveStructCustom{ // want "B, D are missing in ExhaustiveStructCustom" - A: "a", - c: false, - E: time.Now(), - } - - // failPrivate - _ = ExhaustiveStructCustom{ // want "c is missing in ExhaustiveStructCustom" - A: "a", - B: 0, - D: 1.0, - E: time.Now(), - } - -} - -type ExhaustiveStructCustom1 struct { - A string - B int - c bool // private field inside the same package are not ignored - D float64 - E time.Time -} - -func exhaustiveStructCustom1() { - _ = ExhaustiveStructCustom1{ - A: "a", - B: 0, - c: false, - D: 1.0, - E: time.Now(), - } - - _ = ExhaustiveStructCustom1{ - A: "a", - c: false, - D: 1.0, - E: time.Now(), - } - - _ = ExhaustiveStructCustom1{ - A: "a", - c: false, - E: time.Now(), - } - - _ = ExhaustiveStructCustom1{ - A: "a", - B: 0, - D: 1.0, - E: time.Now(), - } -} - -type ExhaustiveStructCustom2 struct { - A string - B int - c bool // private field inside the same package are not ignored - D float64 - E time.Time -} - -func exhaustiveStructCustom2() { - // pass - _ = ExhaustiveStructCustom2{ - A: "a", - B: 0, - c: false, - D: 1.0, - E: time.Now(), - } - - // fail - _ = ExhaustiveStructCustom2{ // want "B is missing in ExhaustiveStructCustom2" - A: "a", - c: false, - D: 1.0, - E: time.Now(), - } - - // failMultiple - _ = ExhaustiveStructCustom2{ // want "B, D are missing in ExhaustiveStructCustom2" - A: "a", - c: false, - E: time.Now(), - } - - // failPrivate - _ = ExhaustiveStructCustom2{ // want "c is missing in ExhaustiveStructCustom2" - A: "a", - B: 0, - D: 1.0, - E: time.Now(), - } - -} diff --git a/test/testdata/golint.go b/test/testdata/golint.go deleted file mode 100644 index feb52f007fbb..000000000000 --- a/test/testdata/golint.go +++ /dev/null @@ -1,22 +0,0 @@ -//golangcitest:args -Egolint --internal-cmd-test -package testdata - -var Go_lint string // want "don't use underscores in Go names; var `Go_lint` should be `GoLint`" - -func ExportedFuncWithNoComment() { -} - -var ExportedVarWithNoComment string - -type ExportedStructWithNoComment struct{} - -type ExportedInterfaceWithNoComment interface{} - -// Bad comment -func ExportedFuncWithBadComment() {} - -type GolintTest struct{} - -func (receiver1 GolintTest) A() {} - -func (receiver2 GolintTest) B() {} // want "receiver name receiver2 should be consistent with previous receiver name receiver1 for GolintTest" diff --git a/test/testdata/ifshort.go b/test/testdata/ifshort.go deleted file mode 100644 index 71906fa850b8..000000000000 --- a/test/testdata/ifshort.go +++ /dev/null @@ -1,13 +0,0 @@ -//go:build !windows - -//golangcitest:args -Eifshort --internal-cmd-test -package testdata - -func DontUseShortSyntaxWhenPossible() { - getValue := func() interface{} { return nil } - - v := getValue() // want "variable 'v' is only used in the if-statement .*" - if v != nil { - return - } -} diff --git a/test/testdata/interfacer.go b/test/testdata/interfacer.go deleted file mode 100644 index 59e64e35656c..000000000000 --- a/test/testdata/interfacer.go +++ /dev/null @@ -1,8 +0,0 @@ -//golangcitest:args -Einterfacer --internal-cmd-test -package testdata - -import "io" - -func InterfacerCheck(f io.ReadCloser) { // want "`f` can be `io.Closer`" - f.Close() -} diff --git a/test/testdata/maligned.go b/test/testdata/maligned.go deleted file mode 100644 index 553fd53ac656..000000000000 --- a/test/testdata/maligned.go +++ /dev/null @@ -1,8 +0,0 @@ -//golangcitest:args -Emaligned --internal-cmd-test -package testdata - -type BadAlignedStruct struct { // want "struct of size 24 bytes could be of size 16 bytes" - B bool - I int - B2 bool -} diff --git a/test/testdata/nosnakecase.go b/test/testdata/nosnakecase.go deleted file mode 100644 index 5a0d207337af..000000000000 --- a/test/testdata/nosnakecase.go +++ /dev/null @@ -1,149 +0,0 @@ -//golangcitest:args -Enosnakecase --internal-cmd-test -package testdata - -import ( - _ "fmt" - f_m_t "fmt" // want "f_m_t contains underscore. You should use mixedCap or MixedCap." -) - -// global variable name with underscore. -var v_v = 0 // want "v_v contains underscore. You should use mixedCap or MixedCap." - -// global constant name with underscore. -const c_c = 0 // want "c_c contains underscore. You should use mixedCap or MixedCap." - -// struct name with underscore. -type S_a struct { // want "S_a contains underscore. You should use mixedCap or MixedCap." - fi int -} - -// non-exported struct field name with underscore. -type Sa struct { - fi_a int // // want "fi_a contains underscore. You should use mixedCap or MixedCap." -} - -// function as struct field, with parameter name with underscore. -type Sb struct { - fib func(p_a int) // want "p_a contains underscore. You should use mixedCap or MixedCap." -} - -// exported struct field with underscore. -type Sc struct { - Fi_A int // want "Fi_A contains underscore. You should use mixedCap or MixedCap." -} - -// function as struct field, with return name with underscore. -type Sd struct { - fib func(p int) (r_a int) // want "r_a contains underscore. You should use mixedCap or MixedCap." -} - -// interface name with underscore. -type I_a interface { // want "I_a contains underscore. You should use mixedCap or MixedCap." - fn(p int) -} - -// interface with parameter name with underscore. -type Ia interface { - fn(p_a int) // want "p_a contains underscore. You should use mixedCap or MixedCap." -} - -// interface with parameter name with underscore. -type Ib interface { - Fn(p_a int) // want "p_a contains underscore. You should use mixedCap or MixedCap." -} - -// function as struct field, with return name with underscore. -type Ic interface { - Fn_a() // want "Fn_a contains underscore. You should use mixedCap or MixedCap." -} - -// interface with return name with underscore. -type Id interface { - Fn() (r_a int) // want "r_a contains underscore. You should use mixedCap or MixedCap." -} - -// function name with underscore. -func f_a() {} // want "f_a contains underscore. You should use mixedCap or MixedCap." - -// function's parameter name with underscore. -func fb(p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." - -// named return with underscore. -func fc() (r_b int) { // want "r_b contains underscore. You should use mixedCap or MixedCap." - return 0 -} - -// local variable (short declaration) with underscore. -func fd(p int) int { - v_b := p * 2 // want "v_b contains underscore. You should use mixedCap or MixedCap." - - return v_b // want "v_b contains underscore. You should use mixedCap or MixedCap." -} - -// local constant with underscore. -func fe(p int) int { - const v_b = 2 // want "v_b contains underscore. You should use mixedCap or MixedCap." - - return v_b * p // want "v_b contains underscore. You should use mixedCap or MixedCap." -} - -// local variable with underscore. -func ff(p int) int { - var v_b = 2 // want "v_b contains underscore. You should use mixedCap or MixedCap." - - return v_b * p // want "v_b contains underscore. You should use mixedCap or MixedCap." -} - -// inner function, parameter name with underscore. -func fg() { - fgl := func(p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." - fgl(1) -} - -type Foo struct{} - -// method name with underscore. -func (f Foo) f_a() {} // want "f_a contains underscore. You should use mixedCap or MixedCap." - -// method's parameter name with underscore. -func (f Foo) fb(p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." - -// named return with underscore. -func (f Foo) fc() (r_b int) { return 0 } // want "r_b contains underscore. You should use mixedCap or MixedCap." - -// local variable (short declaration) with underscore. -func (f Foo) fd(p int) int { - v_b := p * 2 // want "v_b contains underscore. You should use mixedCap or MixedCap." - - return v_b // want "v_b contains underscore. You should use mixedCap or MixedCap." -} - -// local constant with underscore. -func (f Foo) fe(p int) int { - const v_b = 2 // want "v_b contains underscore. You should use mixedCap or MixedCap." - - return v_b * p // want "v_b contains underscore. You should use mixedCap or MixedCap." -} - -// local variable with underscore. -func (f Foo) ff(p int) int { - var v_b = 2 // want "v_b contains underscore. You should use mixedCap or MixedCap." - - return v_b * p // want "v_b contains underscore. You should use mixedCap or MixedCap." -} - -func fna(a, p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." - -func fna1(a string, p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." - -func fnb(a, b, p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." - -func fnb1(a, b string, p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." - -func fnd( - p_a int, // want "p_a contains underscore. You should use mixedCap or MixedCap." - p_b int, // want "p_b contains underscore. You should use mixedCap or MixedCap." - p_c int, // want "p_c contains underscore. You should use mixedCap or MixedCap." -) { - f_m_t.Println("") // want "f_m_t contains underscore. You should use mixedCap or MixedCap." -} diff --git a/test/testdata/scopelint.go b/test/testdata/scopelint.go deleted file mode 100644 index 3afd2f06aba5..000000000000 --- a/test/testdata/scopelint.go +++ /dev/null @@ -1,17 +0,0 @@ -//golangcitest:args -Escopelint --internal-cmd-test -package testdata - -import "fmt" - -func ScopelintTest() { - values := []string{"a", "b", "c"} - var funcs []func() - for _, val := range values { - funcs = append(funcs, func() { - fmt.Println(val) // want "Using the variable on range scope `val` in function literal" - }) - } - for _, f := range funcs { - f() - } -} diff --git a/test/testdata/structcheck.go b/test/testdata/structcheck.go deleted file mode 100644 index 88f06e4d9e48..000000000000 --- a/test/testdata/structcheck.go +++ /dev/null @@ -1,6 +0,0 @@ -//golangcitest:args -Estructcheck -package testdata - -type t struct { - unusedField int // want "`unusedField` is unused" -} diff --git a/test/testdata/varcheck.go b/test/testdata/varcheck.go deleted file mode 100644 index 858c236d2010..000000000000 --- a/test/testdata/varcheck.go +++ /dev/null @@ -1,4 +0,0 @@ -//golangcitest:args -Evarcheck --internal-cmd-test -package testdata - -var v string // want "`v` is unused" From 0e0ea33d58292a01c7c4266e8827085d094bfc1b Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 27 Feb 2024 23:19:41 +0100 Subject: [PATCH 3/6] chore: clean reference file --- .golangci.reference.yml | 64 +++++++---------------------------------- 1 file changed, 10 insertions(+), 54 deletions(-) diff --git a/.golangci.reference.yml b/.golangci.reference.yml index bcf0e5f097dc..8d27601b21be 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -369,16 +369,6 @@ linters-settings: # Default: false default-case-required: true - exhaustivestruct: - # Struct Patterns is list of expressions to match struct packages and names. - # The struct packages have the form `example.com/package.ExampleStruct`. - # The matching patterns can use matching syntax from https://pkg.go.dev/path#Match. - # If this list is empty, all structs are tested. - # Default: [] - struct-patterns: - - '*.Test' - - 'example.com/package.ExampleStruct' - exhaustruct: # List of regular expressions to match struct packages and their names. # Regular expressions must match complete canonical struct package/name/structname. @@ -772,11 +762,6 @@ linters-settings: # Default: "" local-prefixes: github.com/org/project - golint: - # Minimal confidence for issues. - # Default: 0.8 - min-confidence: 0.7 - gomnd: # List of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description. # Default: ["argument", "case", "condition", "operation", "return", "assign"] @@ -1241,15 +1226,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 @@ -1353,11 +1329,6 @@ linters-settings: # Default: false always: true - maligned: - # Print struct with more effective memory layout or not. - # Default: false - suggest-new: true - misspell: # Correct spellings using locale preferences for US or UK. # Setting locale to US will correct the British spelling of 'colour' to 'color'. @@ -2338,11 +2309,6 @@ linters-settings: # Default: true generated-is-used: false - varcheck: - # Check usage of exported fields and variables. - # Default: false - exported-fields: true - varnamelen: # The longest distance, in source lines, that is being considered a "small scope". # Variables used in at most this many lines will be ignored. @@ -2519,7 +2485,6 @@ linters: - contextcheck - copyloopvar - cyclop - - deadcode - decorder - depguard - dogsled @@ -2532,7 +2497,6 @@ linters: - errorlint - execinquery - exhaustive - - exhaustivestruct - exhaustruct - exportloopref - forbidigo @@ -2555,7 +2519,6 @@ linters: - gofumpt - goheader - goimports - - golint - gomnd - gomoddirectives - gomodguard @@ -2565,19 +2528,16 @@ linters: - gosmopolitan - govet - grouper - - ifshort - importas - inamedparam - ineffassign - interfacebloat - - interfacer - intrange - ireturn - lll - loggercheck - maintidx - makezero - - maligned - mirror - misspell - musttag @@ -2589,7 +2549,6 @@ linters: - noctx - nolintlint - nonamedreturns - - nosnakecase - nosprintfhostport - paralleltest - perfsprint @@ -2600,12 +2559,10 @@ linters: - reassign - revive - rowserrcheck - - scopelint - sloglint - spancheck - sqlclosecheck - staticcheck - - structcheck - stylecheck - tagalign - tagliatelle @@ -2620,7 +2577,6 @@ linters: - unparam - unused - usestdlibvars - - varcheck - varnamelen - wastedassign - whitespace @@ -2642,7 +2598,6 @@ linters: - contextcheck - copyloopvar - cyclop - - deadcode - decorder - depguard - dogsled @@ -2655,7 +2610,6 @@ linters: - errorlint - execinquery - exhaustive - - exhaustivestruct - exhaustruct - exportloopref - forbidigo @@ -2678,7 +2632,6 @@ linters: - gofumpt - goheader - goimports - - golint - gomnd - gomoddirectives - gomodguard @@ -2688,19 +2641,16 @@ linters: - gosmopolitan - govet - grouper - - ifshort - importas - inamedparam - ineffassign - interfacebloat - - interfacer - intrange - ireturn - lll - loggercheck - maintidx - makezero - - maligned - mirror - misspell - musttag @@ -2712,7 +2662,6 @@ linters: - noctx - nolintlint - nonamedreturns - - nosnakecase - nosprintfhostport - paralleltest - perfsprint @@ -2723,12 +2672,10 @@ linters: - reassign - revive - rowserrcheck - - scopelint - sloglint - spancheck - sqlclosecheck - staticcheck - - structcheck - stylecheck - tagalign - tagliatelle @@ -2743,13 +2690,22 @@ linters: - unparam - unused - usestdlibvars - - varcheck - varnamelen - wastedassign - whitespace - wrapcheck - wsl - zerologlint + - deadcode # Deprecated + - exhaustivestruct # Deprecated + - golint # Deprecated + - ifshort # Deprecated + - interfacer # Deprecated + - maligned # Deprecated + - nosnakecase # Deprecated + - scopelint # Deprecated + - structcheck # Deprecated + - varcheck # Deprecated # Enable presets. # https://golangci-lint.run/usage/linters From d6a6f9f33f77931a4174320aa668f1a60d675923 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 27 Feb 2024 23:34:50 +0100 Subject: [PATCH 4/6] chore: remove linter settings --- pkg/config/linters_settings.go | 194 +++++++++++++-------------------- 1 file changed, 78 insertions(+), 116 deletions(-) diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index e501908ecac8..319daca4b6dc 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -81,9 +81,6 @@ var defaultLintersSettings = LintersSettings{ ModulePath: "", ExtraRules: false, }, - Golint: GoLintSettings{ - MinConfidence: 0.8, - }, Gosec: GoSecSettings{ Concurrency: runtime.NumCPU(), }, @@ -93,10 +90,6 @@ var defaultLintersSettings = LintersSettings{ IgnoreTests: true, WatchForScripts: []string{"Han"}, }, - Ifshort: IfshortSettings{ - MaxDeclLines: 1, - MaxDeclChars: 30, - }, Inamedparam: INamedParamSettings{ SkipSingleParam: false, }, @@ -204,90 +197,84 @@ var defaultLintersSettings = LintersSettings{ } type LintersSettings struct { - Asasalint AsasalintSettings - BiDiChk BiDiChkSettings - CopyLoopVar CopyLoopVarSettings - Cyclop Cyclop - Decorder DecorderSettings - Depguard DepGuardSettings - Dogsled DogsledSettings - Dupl DuplSettings - DupWord DupWordSettings - Errcheck ErrcheckSettings - ErrChkJSON ErrChkJSONSettings - ErrorLint ErrorLintSettings - Exhaustive ExhaustiveSettings - ExhaustiveStruct ExhaustiveStructSettings - Exhaustruct ExhaustructSettings - Forbidigo ForbidigoSettings - Funlen FunlenSettings - Gci GciSettings - GinkgoLinter GinkgoLinterSettings - Gocognit GocognitSettings - Goconst GoConstSettings - Gocritic GoCriticSettings - Gocyclo GoCycloSettings - Godot GodotSettings - Godox GodoxSettings - Gofmt GoFmtSettings - Gofumpt GofumptSettings - Goheader GoHeaderSettings - Goimports GoImportsSettings - Golint GoLintSettings - Gomnd GoMndSettings - GoModDirectives GoModDirectivesSettings - Gomodguard GoModGuardSettings - Gosec GoSecSettings - Gosimple StaticCheckSettings - Gosmopolitan GosmopolitanSettings - Govet GovetSettings - Grouper GrouperSettings - Ifshort IfshortSettings - ImportAs ImportAsSettings - Inamedparam INamedParamSettings - InterfaceBloat InterfaceBloatSettings - Ireturn IreturnSettings - Lll LllSettings - LoggerCheck LoggerCheckSettings - MaintIdx MaintIdxSettings - Makezero MakezeroSettings - Maligned MalignedSettings - Misspell MisspellSettings - MustTag MustTagSettings - Nakedret NakedretSettings - Nestif NestifSettings - NilNil NilNilSettings - Nlreturn NlreturnSettings - NoLintLint NoLintLintSettings - NoNamedReturns NoNamedReturnsSettings - ParallelTest ParallelTestSettings - PerfSprint PerfSprintSettings - Prealloc PreallocSettings - Predeclared PredeclaredSettings - Promlinter PromlinterSettings - ProtoGetter ProtoGetterSettings - Reassign ReassignSettings - Revive ReviveSettings - RowsErrCheck RowsErrCheckSettings - SlogLint SlogLintSettings - Spancheck SpancheckSettings - Staticcheck StaticCheckSettings - Structcheck StructCheckSettings - Stylecheck StaticCheckSettings - TagAlign TagAlignSettings - Tagliatelle TagliatelleSettings - Tenv TenvSettings - Testifylint TestifylintSettings - Testpackage TestpackageSettings - Thelper ThelperSettings - Unparam UnparamSettings - Unused UnusedSettings - UseStdlibVars UseStdlibVarsSettings - Varcheck VarCheckSettings - Varnamelen VarnamelenSettings - Whitespace WhitespaceSettings - Wrapcheck WrapcheckSettings - WSL WSLSettings + Asasalint AsasalintSettings + BiDiChk BiDiChkSettings + CopyLoopVar CopyLoopVarSettings + Cyclop Cyclop + Decorder DecorderSettings + Depguard DepGuardSettings + Dogsled DogsledSettings + Dupl DuplSettings + DupWord DupWordSettings + Errcheck ErrcheckSettings + ErrChkJSON ErrChkJSONSettings + ErrorLint ErrorLintSettings + Exhaustive ExhaustiveSettings + Exhaustruct ExhaustructSettings + Forbidigo ForbidigoSettings + Funlen FunlenSettings + Gci GciSettings + GinkgoLinter GinkgoLinterSettings + Gocognit GocognitSettings + Goconst GoConstSettings + Gocritic GoCriticSettings + Gocyclo GoCycloSettings + Godot GodotSettings + Godox GodoxSettings + Gofmt GoFmtSettings + Gofumpt GofumptSettings + Goheader GoHeaderSettings + Goimports GoImportsSettings + Gomnd GoMndSettings + GoModDirectives GoModDirectivesSettings + Gomodguard GoModGuardSettings + Gosec GoSecSettings + Gosimple StaticCheckSettings + Gosmopolitan GosmopolitanSettings + Govet GovetSettings + Grouper GrouperSettings + ImportAs ImportAsSettings + Inamedparam INamedParamSettings + InterfaceBloat InterfaceBloatSettings + Ireturn IreturnSettings + Lll LllSettings + LoggerCheck LoggerCheckSettings + MaintIdx MaintIdxSettings + Makezero MakezeroSettings + Misspell MisspellSettings + MustTag MustTagSettings + Nakedret NakedretSettings + Nestif NestifSettings + NilNil NilNilSettings + Nlreturn NlreturnSettings + NoLintLint NoLintLintSettings + NoNamedReturns NoNamedReturnsSettings + ParallelTest ParallelTestSettings + PerfSprint PerfSprintSettings + Prealloc PreallocSettings + Predeclared PredeclaredSettings + Promlinter PromlinterSettings + ProtoGetter ProtoGetterSettings + Reassign ReassignSettings + Revive ReviveSettings + RowsErrCheck RowsErrCheckSettings + SlogLint SlogLintSettings + Spancheck SpancheckSettings + Staticcheck StaticCheckSettings + Stylecheck StaticCheckSettings + TagAlign TagAlignSettings + Tagliatelle TagliatelleSettings + Tenv TenvSettings + Testifylint TestifylintSettings + Testpackage TestpackageSettings + Thelper ThelperSettings + Unparam UnparamSettings + Unused UnusedSettings + UseStdlibVars UseStdlibVarsSettings + Varnamelen VarnamelenSettings + Whitespace WhitespaceSettings + Wrapcheck WrapcheckSettings + WSL WSLSettings Custom map[string]CustomLinterSettings } @@ -399,10 +386,6 @@ type ExhaustiveSettings struct { DefaultCaseRequired bool `mapstructure:"default-case-required"` } -type ExhaustiveStructSettings struct { - StructPatterns []string `mapstructure:"struct-patterns"` -} - type ExhaustructSettings struct { Include []string `mapstructure:"include"` Exclude []string `mapstructure:"exclude"` @@ -549,10 +532,6 @@ type GoImportsSettings struct { LocalPrefixes string `mapstructure:"local-prefixes"` } -type GoLintSettings struct { - MinConfidence float64 `mapstructure:"min-confidence"` -} - type GoMndSettings struct { Settings map[string]map[string]any // Deprecated Checks []string `mapstructure:"checks"` @@ -638,11 +617,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"` @@ -690,10 +664,6 @@ type MakezeroSettings struct { Always bool } -type MalignedSettings struct { - SuggestNewOrder bool `mapstructure:"suggest-new"` -} - type MisspellSettings struct { Mode string `mapstructure:"mode"` Locale string `mapstructure:"locale"` @@ -838,10 +808,6 @@ func (s *StaticCheckSettings) HasConfiguration() bool { return len(s.Initialisms) > 0 || len(s.HTTPStatusCodeWhitelist) > 0 || len(s.DotImportWhitelist) > 0 || len(s.Checks) > 0 } -type StructCheckSettings struct { - CheckExportedFields bool `mapstructure:"exported-fields"` -} - type TagAlignSettings struct { Align bool `mapstructure:"align"` Sort bool `mapstructure:"sort"` @@ -931,10 +897,6 @@ type UnusedSettings struct { GeneratedIsUsed bool `mapstructure:"generated-is-used"` } -type VarCheckSettings struct { - CheckExportedFields bool `mapstructure:"exported-fields"` -} - type VarnamelenSettings struct { MaxDistance int `mapstructure:"max-distance"` MinNameLength int `mapstructure:"min-name-length"` From f3d02136f4bb25084d1c552f4b1bba124cb2deed Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 3 Mar 2024 16:47:28 +0100 Subject: [PATCH 5/6] review: add a reason --- pkg/lint/linter/linter.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/lint/linter/linter.go b/pkg/lint/linter/linter.go index 45f62bc3d8cb..efa69b7f1fcd 100644 --- a/pkg/lint/linter/linter.go +++ b/pkg/lint/linter/linter.go @@ -28,8 +28,9 @@ func NewNoop(l Linter, reason string) Noop { func NewNoopDeprecated(name string) Noop { return Noop{ - name: name, - desc: "Deprecated", + name: name, + desc: "Deprecated", + reason: "This linter is fully inactivated: it will not produce any reports.", } } From 39d7adb5916396da6f443fa3fadb140bb58758e8 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 3 Mar 2024 17:41:40 +0100 Subject: [PATCH 6/6] chore: hide log for internal tests --- pkg/lint/linter/linter.go | 11 +++++++++-- pkg/lint/lintersdb/builder_linter.go | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pkg/lint/linter/linter.go b/pkg/lint/linter/linter.go index efa69b7f1fcd..1d4e7b04ccce 100644 --- a/pkg/lint/linter/linter.go +++ b/pkg/lint/linter/linter.go @@ -3,6 +3,7 @@ package linter import ( "context" + "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/result" ) @@ -26,12 +27,18 @@ func NewNoop(l Linter, reason string) Noop { } } -func NewNoopDeprecated(name string) Noop { - return Noop{ +func NewNoopDeprecated(name string, cfg *config.Config) Noop { + noop := Noop{ name: name, desc: "Deprecated", reason: "This linter is fully inactivated: it will not produce any reports.", } + + if cfg.InternalCmdTest { + noop.reason = "" + } + + return noop } func (n Noop) Run(_ context.Context, lintCtx *Context) ([]result.Issue, error) { diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index eba79f3d0e5c..c239a9b84ba6 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -77,7 +77,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithPresets(linter.PresetFormatting, linter.PresetStyle). WithURL("https://gitlab.com/bosi/decorder"), - linter.NewConfig(linter.NewNoopDeprecated("deadcode")). + linter.NewConfig(linter.NewNoopDeprecated("deadcode", cfg)). WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetUnused). @@ -148,7 +148,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithLoadForGoAnalysis(). WithURL("https://github.com/nishanths/exhaustive"), - linter.NewConfig(linter.NewNoopDeprecated("exhaustivestruct")). + linter.NewConfig(linter.NewNoopDeprecated("exhaustivestruct", cfg)). WithSince("v1.32.0"). WithPresets(linter.PresetStyle, linter.PresetTest). WithLoadForGoAnalysis(). @@ -280,7 +280,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithAutoFix(). WithURL("https://pkg.go.dev/golang.org/x/tools/cmd/goimports"), - linter.NewConfig(linter.NewNoopDeprecated("golint")). + linter.NewConfig(linter.NewNoopDeprecated("golint", cfg)). WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetStyle). @@ -341,7 +341,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/leonklingele/grouper"), - linter.NewConfig(linter.NewNoopDeprecated("ifshort")). + linter.NewConfig(linter.NewNoopDeprecated("ifshort", cfg)). WithSince("v1.36.0"). WithPresets(linter.PresetStyle). WithURL("https://github.com/esimonov/ifshort"). @@ -369,7 +369,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/sashamelentyev/interfacebloat"), - linter.NewConfig(linter.NewNoopDeprecated("interfacer")). + linter.NewConfig(linter.NewNoopDeprecated("interfacer", cfg)). WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetStyle). @@ -409,7 +409,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithLoadForGoAnalysis(). WithURL("https://github.com/ashanbrown/makezero"), - linter.NewConfig(linter.NewNoopDeprecated("maligned")). + linter.NewConfig(linter.NewNoopDeprecated("maligned", cfg)). WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetPerformance). @@ -473,7 +473,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/firefart/nonamedreturns"), - linter.NewConfig(linter.NewNoopDeprecated("nosnakecase")). + linter.NewConfig(linter.NewNoopDeprecated("nosnakecase", cfg)). WithSince("v1.47.0"). WithPresets(linter.PresetStyle). WithURL("https://github.com/sivchari/nosnakecase"). @@ -542,7 +542,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithPresets(linter.PresetStyle, linter.PresetFormatting). WithURL("https://github.com/go-simpler/sloglint"), - linter.NewConfig(linter.NewNoopDeprecated("scopelint")). + linter.NewConfig(linter.NewNoopDeprecated("scopelint", cfg)). WithSince("v1.12.0"). WithPresets(linter.PresetBugs). WithURL("https://github.com/kyoh86/scopelint"). @@ -568,7 +568,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithAlternativeNames(megacheckName). WithURL("https://staticcheck.io/"), - linter.NewConfig(linter.NewNoopDeprecated("structcheck")). + linter.NewConfig(linter.NewNoopDeprecated("structcheck", cfg)). WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetUnused). @@ -661,7 +661,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/sashamelentyev/usestdlibvars"), - linter.NewConfig(linter.NewNoopDeprecated("varcheck")). + linter.NewConfig(linter.NewNoopDeprecated("varcheck", cfg)). WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetUnused).