From 8f2459bf0ea3f9add4aae7dcce260d941ff4b8ee Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Mon, 4 Mar 2024 14:15:41 +0100 Subject: [PATCH] fix: move show-stats field from run to output (#4439) --- .golangci.reference.yml | 7 +++---- .golangci.yml | 11 +++++++++++ pkg/commands/flagsets.go | 2 +- pkg/commands/run.go | 6 +++++- pkg/config/output.go | 1 + pkg/config/run.go | 1 + 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.golangci.reference.yml b/.golangci.reference.yml index 8d27601b21be..400faa6a4cea 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -80,10 +80,6 @@ run: # Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.17 go: '1.19' - # Show statistics per linter. - # Default: false - show-stats: true - # output configuration options output: @@ -117,6 +113,9 @@ output: # Default: false sort-results: true + # Show statistics per linter. + # Default: false + show-stats: true # All available settings of specific linters. linters-settings: diff --git a/.golangci.yml b/.golangci.yml index b56d9fddaf81..322ed8dc0082 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -138,19 +138,30 @@ issues: - gomnd - path: pkg/golinters/errcheck.go + linters: [staticcheck] text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead" - path: pkg/commands/run.go + linters: [staticcheck] text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead" + - path: pkg/commands/run.go + linters: [staticcheck] + text: "SA1019: c.cfg.Run.ShowStats is deprecated: use Output.ShowStats instead." - path: pkg/golinters/gofumpt.go + linters: [staticcheck] text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead." - path: pkg/golinters/staticcheck_common.go + linters: [staticcheck] text: "SA1019: settings.GoVersion is deprecated: use the global `run.go` instead." - path: pkg/lint/lintersdb/manager.go + linters: [staticcheck] text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead." + - path: pkg/golinters/unused.go + linters: [gocritic] text: "rangeValCopy: each iteration copies 160 bytes \\(consider pointers or indexing\\)" - path: test/(fix|linters)_test.go + linters: [gocritic] text: "string `gocritic.go` has 3 occurrences, make it a constant" run: diff --git a/pkg/commands/flagsets.go b/pkg/commands/flagsets.go index 0928b41e3a0f..4ba1f2adb3dd 100644 --- a/pkg/commands/flagsets.go +++ b/pkg/commands/flagsets.go @@ -55,7 +55,6 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) { const allowSerialDesc = "Allow multiple golangci-lint instances running, but serialize them around a lock. " + "If false (default) - golangci-lint exits with an error if it fails to acquire file lock on start." internal.AddFlagAndBind(v, fs, fs.Bool, "allow-serial-runners", "run.allow-serial-runners", false, color.GreenString(allowSerialDesc)) - internal.AddFlagAndBind(v, fs, fs.Bool, "show-stats", "run.show-stats", false, color.GreenString("Show statistics per linter")) } func setupOutputFlagSet(v *viper.Viper, fs *pflag.FlagSet) { @@ -71,6 +70,7 @@ func setupOutputFlagSet(v *viper.Viper, fs *pflag.FlagSet) { color.GreenString("Sort linter results")) internal.AddFlagAndBind(v, fs, fs.String, "path-prefix", "output.path-prefix", "", color.GreenString("Path prefix to add to output")) + internal.AddFlagAndBind(v, fs, fs.Bool, "show-stats", "output.show-stats", false, color.GreenString("Show statistics per linter")) } //nolint:gomnd diff --git a/pkg/commands/run.go b/pkg/commands/run.go index cf1acfd620b9..60f241af3a7f 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -397,7 +397,11 @@ func (c *runCommand) setExitCodeIfIssuesFound(issues []result.Issue) { } func (c *runCommand) printStats(issues []result.Issue) { - if !c.cfg.Run.ShowStats { + if c.cfg.Run.ShowStats { + c.log.Warnf("The configuration option `run.show-stats` is deprecated, please use `output.show-stats`") + } + + if !c.cfg.Run.ShowStats && !c.cfg.Output.ShowStats { return } diff --git a/pkg/config/output.go b/pkg/config/output.go index 95af38885a67..c882e2152aaa 100644 --- a/pkg/config/output.go +++ b/pkg/config/output.go @@ -34,4 +34,5 @@ type Output struct { UniqByLine bool `mapstructure:"uniq-by-line"` SortResults bool `mapstructure:"sort-results"` PathPrefix string `mapstructure:"path-prefix"` + ShowStats bool `mapstructure:"show-stats"` } diff --git a/pkg/config/run.go b/pkg/config/run.go index bd81e0d8c21b..8a1e58c37319 100644 --- a/pkg/config/run.go +++ b/pkg/config/run.go @@ -23,6 +23,7 @@ type Run struct { AllowParallelRunners bool `mapstructure:"allow-parallel-runners"` AllowSerialRunners bool `mapstructure:"allow-serial-runners"` + // Deprecated: use Output.ShowStats instead. ShowStats bool `mapstructure:"show-stats"` // It's obtain by flags and use for the tests and the context loader.