From 08deff422526a94181e9b86db604014087bf7128 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Wed, 22 May 2024 23:09:43 +0200 Subject: [PATCH] feat: add warning about disabled and deprecated linters (level 2) (#4742) --- docs/src/docs/product/roadmap.mdx | 7 +++++-- pkg/lint/lintersdb/validator.go | 22 ++++++++++++++++++---- test/run_test.go | 2 -- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/src/docs/product/roadmap.mdx b/docs/src/docs/product/roadmap.mdx index dcca3c88fbce..6753f55e0de0 100644 --- a/docs/src/docs/product/roadmap.mdx +++ b/docs/src/docs/product/roadmap.mdx @@ -47,8 +47,11 @@ A linter can be deprecated for various reasons, e.g. the linter stops working wi The deprecation of a linter will follow 3 phases: -1. **Display of a warning message**: The linter can still be used (unless it's completely non-functional), but it's recommended to remove it from your configuration. -2. **Display of an error message**: At this point, you should remove the linter. The original implementation is replaced by a placeholder that does nothing. +1. **Display of a warning message**: The linter can still be used (unless it's completely non-functional), + but it's recommended to remove it from your configuration. +2. **Display of an error message**: At this point, you should remove the linter. + The original implementation is replaced by a placeholder that does nothing. + The linter is NOT enabled when using `enable-all` and should be removed from the `disable` option. 3. **Removal of the linter** from golangci-lint. Each phase corresponds to a minor version: diff --git a/pkg/lint/lintersdb/validator.go b/pkg/lint/lintersdb/validator.go index 079d8198fa3c..264d063aabb4 100644 --- a/pkg/lint/lintersdb/validator.go +++ b/pkg/lint/lintersdb/validator.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/golangci/golangci-lint/pkg/config" + "github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/logutils" ) @@ -38,17 +39,30 @@ func (v Validator) Validate(cfg *config.Config) error { } func (v Validator) validateLintersNames(cfg *config.Linters) error { - allNames := cfg.Enable - allNames = append(allNames, cfg.Disable...) - var unknownNames []string - for _, name := range allNames { + for _, name := range cfg.Enable { if v.m.GetLinterConfigs(name) == nil { unknownNames = append(unknownNames, name) } } + for _, name := range cfg.Disable { + lcs := v.m.GetLinterConfigs(name) + if len(lcs) == 0 { + unknownNames = append(unknownNames, name) + continue + } + + for _, lc := range lcs { + if lc.IsDeprecated() && lc.Deprecation.Level > linter.DeprecationWarning { + v.m.log.Warnf("The linter %q is deprecated (step 2) and deactivated. "+ + "It should be removed from the list of disabled linters. "+ + "https://golangci-lint.run/product/roadmap/#linter-deprecation-cycle", lc.Name()) + } + } + } + if len(unknownNames) > 0 { return fmt.Errorf("unknown linters: '%v', run 'golangci-lint help linters' to see the list of supported linters", strings.Join(unknownNames, ",")) diff --git a/test/run_test.go b/test/run_test.go index 4c6b870ac07b..9040f0ffd322 100644 --- a/test/run_test.go +++ b/test/run_test.go @@ -100,8 +100,6 @@ func TestCgoOk(t *testing.T) { WithNoConfig(). WithArgs("--timeout=3m", "--enable-all", - "-D", - "nosnakecase", ). WithArgs("--go=1.22"). // TODO(ldez) remove this line when we will run go1.23 on the CI. (related to intrange, copyloopvar) WithTargetPath(testdataDir, "cgo").