From 1741450e3d4402d05e1154b5793eab2a4adef2a3 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 20 Feb 2025 21:55:47 +0100 Subject: [PATCH 1/7] chore: new concurrency default --- .golangci.next.reference.yml | 4 ++-- pkg/commands/flagsets.go | 5 +++-- pkg/commands/run.go | 11 +---------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 5de829806041..650f5da4d3f0 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -4186,8 +4186,8 @@ run: go: '1.19' # Number of operating system threads (`GOMAXPROCS`) that can execute golangci-lint simultaneously. - # If it is explicitly set to 0 (i.e. not the default) then golangci-lint will automatically set the value to match Linux container CPU quota. - # Default: the number of logical CPUs in the machine + # Default: automatically set to match Linux container CPU quota and + # fall back to the number of logical CPUs in the machine. concurrency: 4 diff --git a/pkg/commands/flagsets.go b/pkg/commands/flagsets.go index aee7fd330ff1..3c27f812b275 100644 --- a/pkg/commands/flagsets.go +++ b/pkg/commands/flagsets.go @@ -42,8 +42,9 @@ func setupFormattersFlagSet(v *viper.Viper, fs *pflag.FlagSet) { } func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) { - internal.AddFlagAndBindP(v, fs, fs.IntP, "concurrency", "j", "run.concurrency", getDefaultConcurrency(), - color.GreenString("Number of CPUs to use (Default: number of logical CPUs)")) + internal.AddFlagAndBindP(v, fs, fs.IntP, "concurrency", "j", "run.concurrency", 0, + color.GreenString("Number of CPUs to use (Default: Automatically set to match Linux container CPU quota,"+ + " fall backs on number of logical CPUs)")) internal.AddFlagAndBind(v, fs, fs.String, "modules-download-mode", "run.modules-download-mode", "", color.GreenString("Modules download mode. If not empty, passed as -mod= to go tools")) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 319d6e23fd1b..27130ad8336b 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -161,6 +161,7 @@ func (c *runCommand) persistentPreRunE(cmd *cobra.Command, args []string) error } if c.cfg.Run.Concurrency == 0 { + // `runtime.GOMAXPROCS` defaults to the value of `runtime.NumCPU`. backup := runtime.GOMAXPROCS(0) // Automatically set GOMAXPROCS to match Linux container CPU quota. @@ -590,16 +591,6 @@ func setupRunPersistentFlags(fs *pflag.FlagSet, opts *runOptions) { fs.StringVar(&opts.TracePath, "trace-path", "", color.GreenString("Path to trace output file")) } -func getDefaultConcurrency() int { - if os.Getenv(envHelpRun) == "1" { - // Make stable concurrency for generating help documentation. - const prettyConcurrency = 8 - return prettyConcurrency - } - - return runtime.NumCPU() -} - func printMemStats(ms *runtime.MemStats, logger logutils.Log) { logger.Infof("Mem stats: alloc=%s total_alloc=%s sys=%s "+ "heap_alloc=%s heap_sys=%s heap_idle=%s heap_released=%s heap_in_use=%s "+ From e637ce76fa18d800d28f71d258c22c8bba1474f5 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 20 Feb 2025 23:34:24 +0100 Subject: [PATCH 2/7] chore: new default Go version --- .golangci.next.reference.yml | 4 ++-- pkg/commands/flagsets.go | 1 - pkg/config/config.go | 6 +++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 650f5da4d3f0..7911932d60f2 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -4182,8 +4182,8 @@ run: # Define the Go version limit. # Mainly related to generics support since go1.18. - # Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.17 - go: '1.19' + # Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.22. + go: '1.22' # Number of operating system threads (`GOMAXPROCS`) that can execute golangci-lint simultaneously. # Default: automatically set to match Linux container CPU quota and diff --git a/pkg/commands/flagsets.go b/pkg/commands/flagsets.go index 3c27f812b275..c8aa967a4245 100644 --- a/pkg/commands/flagsets.go +++ b/pkg/commands/flagsets.go @@ -50,7 +50,6 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) { color.GreenString("Modules download mode. If not empty, passed as -mod= to go tools")) internal.AddFlagAndBind(v, fs, fs.Int, "issues-exit-code", "run.issues-exit-code", exitcodes.IssuesFound, color.GreenString("Exit code when issues were found")) - internal.AddFlagAndBind(v, fs, fs.String, "go", "run.go", "", color.GreenString("Targeted Go version")) internal.AddHackedStringSlice(fs, "build-tags", color.GreenString("Build tags")) internal.AddFlagAndBind(v, fs, fs.Duration, "timeout", "run.timeout", defaultTimeout, diff --git a/pkg/config/config.go b/pkg/config/config.go index aa24e3dd33c2..fe72c8d60c3c 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -15,6 +15,10 @@ import ( "golang.org/x/mod/modfile" ) +// defaultGoVersion the value should be "oldstable" - 1. +// If the current stable version is 1.24 then 1.23 - 1 = 1.22. +const defaultGoVersion = "1.22" + // Config encapsulates the config data specified in the golangci-lint YAML config file. type Config struct { cfgDir string // Path to the directory containing golangci-lint config file. @@ -93,7 +97,7 @@ func IsGoGreaterThanOrEqual(current, limit string) bool { } func detectGoVersion(ctx context.Context) string { - return cmp.Or(detectGoVersionFromGoMod(ctx), "1.17") + return cmp.Or(detectGoVersionFromGoMod(ctx), defaultGoVersion) } // detectGoVersionFromGoMod tries to get Go version from go.mod. From d3bf353d4531c824201394821f0119a690a01519 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 19 Feb 2025 16:41:39 +0100 Subject: [PATCH 3/7] chore: new timeout default --- .golangci.next.reference.yml | 2 +- pkg/commands/run.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 7911932d60f2..00f817612994 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -4131,7 +4131,7 @@ output: run: # Timeout for analysis, e.g. 30s, 5m. # If the value is lower or equal to 0, the timeout is disabled. - # Default: 1m + # Default: 15m timeout: 5m # The mode used to evaluate relative paths. diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 27130ad8336b..503381abcf49 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -43,7 +43,7 @@ import ( "github.com/golangci/golangci-lint/pkg/timeutils" ) -const defaultTimeout = time.Minute +const defaultTimeout = 15 * time.Minute const ( // envFailOnWarnings value: "1" From dd462d5024757ea369454ab6b71075f51f1ee205 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 21 Feb 2025 05:18:06 +0100 Subject: [PATCH 4/7] chore: new show-stats default --- .golangci.next.reference.yml | 4 ++-- jsonschema/golangci.next.jsonschema.json | 2 +- pkg/commands/flagsets.go | 2 +- test/run_test.go | 24 ++++++++++++++++++++---- test/testshared/integration/run.go | 1 + 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 00f817612994..3e29d77a823f 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -4123,8 +4123,8 @@ output: - file # filepath, line, and column. # Show statistics per linter. - # Default: false - show-stats: true + # Default: true + show-stats: false # Options for analysis running. diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 4891a5514633..f433462fbd0a 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -3888,7 +3888,7 @@ "show-stats": { "description": "Show statistics per linter.", "type": "boolean", - "default": false + "default": true }, "sort-order": { "type": "array", diff --git a/pkg/commands/flagsets.go b/pkg/commands/flagsets.go index c8aa967a4245..4df7da015ad4 100644 --- a/pkg/commands/flagsets.go +++ b/pkg/commands/flagsets.go @@ -72,7 +72,7 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) { func setupOutputFlagSet(v *viper.Viper, fs *pflag.FlagSet) { 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")) + internal.AddFlagAndBind(v, fs, fs.Bool, "show-stats", "output.show-stats", true, color.GreenString("Show statistics per linter")) setupOutputFormatsFlagSet(v, fs) } diff --git a/test/run_test.go b/test/run_test.go index d607c1f6193e..5dbe7e72750a 100644 --- a/test/run_test.go +++ b/test/run_test.go @@ -37,6 +37,7 @@ func TestAutogeneratedNoIssues(t *testing.T) { testshared.NewRunnerBuilder(t). WithConfig(cfg). + WithArgs("--show-stats=false"). WithTargetPath(testdataDir, "autogenerated"). WithBinPath(binPath). Runner(). @@ -47,6 +48,7 @@ func TestAutogeneratedNoIssues(t *testing.T) { func TestEmptyDirRun(t *testing.T) { testshared.NewRunnerBuilder(t). WithEnviron("GO111MODULE=off"). + WithArgs("--show-stats=false"). WithTargetPath(testdataDir, "nogofiles"). Runner(). Install(). @@ -69,6 +71,7 @@ func TestNotExistingDirRun(t *testing.T) { func TestSymlinkLoop(t *testing.T) { testshared.NewRunnerBuilder(t). + WithArgs("--show-stats=false"). WithTargetPath(testdataDir, "symlink_loop", "..."). Runner(). Install(). @@ -120,7 +123,9 @@ func TestTestsAreLintedByDefault(t *testing.T) { func TestCgoOk(t *testing.T) { testshared.NewRunnerBuilder(t). WithNoConfig(). - WithArgs("--timeout=3m", + WithArgs( + "--timeout=3m", + "--show-stats=false", "--enable-all", ). WithTargetPath(testdataDir, "cgo"). @@ -358,7 +363,10 @@ func TestUnsafeOk(t *testing.T) { testshared.NewRunnerBuilder(t). WithConfig(cfg). - WithArgs("--enable-all"). + WithArgs( + "--show-stats=false", + "--enable-all", + ). WithTargetPath(testdataDir, "unsafe"). WithBinPath(binPath). Runner(). @@ -371,7 +379,10 @@ func TestSortedResults(t *testing.T) { testshared.NewRunnerBuilder(t). WithNoConfig(). - WithArgs("--output.text.print-issued-lines=false"). + WithArgs( + "--show-stats=false", + "--output.text.print-issued-lines=false", + ). WithTargetPath(testdataDir, "sort_results"). WithBinPath(binPath). Runner(). @@ -385,7 +396,11 @@ func TestSortedResults(t *testing.T) { func TestIdentifierUsedOnlyInTests(t *testing.T) { testshared.NewRunnerBuilder(t). WithNoConfig(). - WithArgs("--disable-all", "-Eunused"). + WithArgs( + "--show-stats=false", + "--disable-all", + "-Eunused", + ). WithTargetPath(testdataDir, "used_only_in_tests"). Runner(). Install(). @@ -395,6 +410,7 @@ func TestIdentifierUsedOnlyInTests(t *testing.T) { func TestUnusedCheckExported(t *testing.T) { testshared.NewRunnerBuilder(t). + WithArgs("--show-stats=false"). WithConfigFile("testdata_etc/unused_exported/golangci.yml"). WithTargetPath("testdata_etc/unused_exported/..."). Runner(). diff --git a/test/testshared/integration/run.go b/test/testshared/integration/run.go index 3aa6e289c202..5d69be775e7b 100644 --- a/test/testshared/integration/run.go +++ b/test/testshared/integration/run.go @@ -63,6 +63,7 @@ func testOneSource(t *testing.T, log *logutils.StderrLog, binPath, sourcePath st args := []string{ "--disable-all", + "--show-stats=false", "--output.json.path=stdout", "--max-same-issues=100", "--max-issues-per-linter=100", From bf1ad2b9b1a0539cd19a952d9e11b94667566360 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 25 Feb 2025 00:17:52 +0100 Subject: [PATCH 5/7] review: disable timeout by default --- .golangci.next.reference.yml | 2 +- .golangci.yml | 2 -- jsonschema/golangci.next.jsonschema.json | 4 ++-- pkg/commands/flagsets.go | 2 +- pkg/commands/run.go | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 3e29d77a823f..88a67f023879 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -4131,7 +4131,7 @@ output: run: # Timeout for analysis, e.g. 30s, 5m. # If the value is lower or equal to 0, the timeout is disabled. - # Default: 15m + # Default: 0 (disabled) timeout: 5m # The mode used to evaluate relative paths. diff --git a/.golangci.yml b/.golangci.yml index 06bab229429c..f39cb811a799 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -202,5 +202,3 @@ linters-settings: - name: unused-parameter - name: unused-receiver -run: - timeout: 5m diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index f433462fbd0a..25231fdea79c 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -3744,10 +3744,10 @@ "examples": [4] }, "timeout": { - "description": "Timeout for the analysis.", + "description": "Timeout for total work. Disabled by default", "type": "string", "pattern": "^\\d*[sm]$", - "default": "1m", + "default": "0", "examples": ["30s", "5m"] }, "issues-exit-code": { diff --git a/pkg/commands/flagsets.go b/pkg/commands/flagsets.go index 4df7da015ad4..6273b6e937c1 100644 --- a/pkg/commands/flagsets.go +++ b/pkg/commands/flagsets.go @@ -53,7 +53,7 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) { internal.AddHackedStringSlice(fs, "build-tags", color.GreenString("Build tags")) internal.AddFlagAndBind(v, fs, fs.Duration, "timeout", "run.timeout", defaultTimeout, - color.GreenString("Timeout for total work. If <= 0, the timeout is disabled")) + color.GreenString("Timeout for total work. Disabled by default")) internal.AddFlagAndBind(v, fs, fs.Bool, "tests", "run.tests", true, color.GreenString("Analyze tests (*_test.go)")) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 503381abcf49..c1f028c07739 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -43,7 +43,7 @@ import ( "github.com/golangci/golangci-lint/pkg/timeutils" ) -const defaultTimeout = 15 * time.Minute +const defaultTimeout = 0 * time.Minute const ( // envFailOnWarnings value: "1" From 07e0213170bfe7fc78eeb0995fdbfbd9878feb07 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 25 Feb 2025 02:29:11 +0100 Subject: [PATCH 6/7] fix: the context Done chan should be closed when using verbose mode --- pkg/commands/run.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index c1f028c07739..a668521316c1 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -246,12 +246,11 @@ func (c *runCommand) execute(_ *cobra.Command, _ []string) { } }() - ctx := context.Background() + ctx, cancel := context.WithCancel(context.Background()) if c.cfg.Run.Timeout > 0 { - var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, c.cfg.Run.Timeout) - defer cancel() } + defer cancel() if needTrackResources { go watchResources(ctx, trackResourcesEndCh, c.log, c.debugf) From 91f4f260d44ba2904daccf2fdc9758038c9b3114 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 25 Feb 2025 12:58:09 +0100 Subject: [PATCH 7/7] review --- .golangci.next.reference.yml | 9 ++++----- pkg/commands/flagsets.go | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 88a67f023879..5c445cbd2bd5 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -4129,7 +4129,7 @@ output: # Options for analysis running. run: - # Timeout for analysis, e.g. 30s, 5m. + # Timeout for total work, e.g. 30s, 5m. # If the value is lower or equal to 0, the timeout is disabled. # Default: 0 (disabled) timeout: 5m @@ -4181,13 +4181,12 @@ run: allow-serial-runners: true # Define the Go version limit. - # Mainly related to generics support since go1.18. # Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.22. - go: '1.22' + go: '1.23' # Number of operating system threads (`GOMAXPROCS`) that can execute golangci-lint simultaneously. - # Default: automatically set to match Linux container CPU quota and - # fall back to the number of logical CPUs in the machine. + # Default: 0 (automatically set to match Linux container CPU quota and + # fall back to the number of logical CPUs in the machine) concurrency: 4 diff --git a/pkg/commands/flagsets.go b/pkg/commands/flagsets.go index 6273b6e937c1..4081501eb28d 100644 --- a/pkg/commands/flagsets.go +++ b/pkg/commands/flagsets.go @@ -43,8 +43,8 @@ func setupFormattersFlagSet(v *viper.Viper, fs *pflag.FlagSet) { func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) { internal.AddFlagAndBindP(v, fs, fs.IntP, "concurrency", "j", "run.concurrency", 0, - color.GreenString("Number of CPUs to use (Default: Automatically set to match Linux container CPU quota,"+ - " fall backs on number of logical CPUs)")) + color.GreenString("Number of CPUs to use (Default: Automatically set to match Linux container CPU quota"+ + " and fall back to the number of logical CPUs in the machine)")) internal.AddFlagAndBind(v, fs, fs.String, "modules-download-mode", "run.modules-download-mode", "", color.GreenString("Modules download mode. If not empty, passed as -mod= to go tools"))