Skip to content

Commit 45f39cc

Browse files
authored
feat: new default values (#5470)
1 parent 18e322e commit 45f39cc

File tree

8 files changed

+46
-38
lines changed

8 files changed

+46
-38
lines changed

.golangci.next.reference.yml

+8-9
Original file line numberDiff line numberDiff line change
@@ -4123,15 +4123,15 @@ output:
41234123
- file # filepath, line, and column.
41244124

41254125
# Show statistics per linter.
4126-
# Default: false
4127-
show-stats: true
4126+
# Default: true
4127+
show-stats: false
41284128

41294129

41304130
# Options for analysis running.
41314131
run:
4132-
# Timeout for analysis, e.g. 30s, 5m.
4132+
# Timeout for total work, e.g. 30s, 5m.
41334133
# If the value is lower or equal to 0, the timeout is disabled.
4134-
# Default: 1m
4134+
# Default: 0 (disabled)
41354135
timeout: 5m
41364136

41374137
# The mode used to evaluate relative paths.
@@ -4181,13 +4181,12 @@ run:
41814181
allow-serial-runners: true
41824182

41834183
# Define the Go version limit.
4184-
# Mainly related to generics support since go1.18.
4185-
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.17
4186-
go: '1.19'
4184+
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.22.
4185+
go: '1.23'
41874186

41884187
# Number of operating system threads (`GOMAXPROCS`) that can execute golangci-lint simultaneously.
4189-
# 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.
4190-
# Default: the number of logical CPUs in the machine
4188+
# Default: 0 (automatically set to match Linux container CPU quota and
4189+
# fall back to the number of logical CPUs in the machine)
41914190
concurrency: 4
41924191

41934192

.golangci.yml

-2
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,3 @@ linters-settings:
202202
- name: unused-parameter
203203
- name: unused-receiver
204204

205-
run:
206-
timeout: 5m

jsonschema/golangci.next.jsonschema.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -3744,10 +3744,10 @@
37443744
"examples": [4]
37453745
},
37463746
"timeout": {
3747-
"description": "Timeout for the analysis.",
3747+
"description": "Timeout for total work. Disabled by default",
37483748
"type": "string",
37493749
"pattern": "^\\d*[sm]$",
3750-
"default": "1m",
3750+
"default": "0",
37513751
"examples": ["30s", "5m"]
37523752
},
37533753
"issues-exit-code": {
@@ -3888,7 +3888,7 @@
38883888
"show-stats": {
38893889
"description": "Show statistics per linter.",
38903890
"type": "boolean",
3891-
"default": false
3891+
"default": true
38923892
},
38933893
"sort-order": {
38943894
"type": "array",

pkg/commands/flagsets.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ func setupFormattersFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
4242
}
4343

4444
func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
45-
internal.AddFlagAndBindP(v, fs, fs.IntP, "concurrency", "j", "run.concurrency", getDefaultConcurrency(),
46-
color.GreenString("Number of CPUs to use (Default: number of logical CPUs)"))
45+
internal.AddFlagAndBindP(v, fs, fs.IntP, "concurrency", "j", "run.concurrency", 0,
46+
color.GreenString("Number of CPUs to use (Default: Automatically set to match Linux container CPU quota"+
47+
" and fall back to the number of logical CPUs in the machine)"))
4748

4849
internal.AddFlagAndBind(v, fs, fs.String, "modules-download-mode", "run.modules-download-mode", "",
4950
color.GreenString("Modules download mode. If not empty, passed as -mod=<mode> to go tools"))
5051
internal.AddFlagAndBind(v, fs, fs.Int, "issues-exit-code", "run.issues-exit-code", exitcodes.IssuesFound,
5152
color.GreenString("Exit code when issues were found"))
52-
internal.AddFlagAndBind(v, fs, fs.String, "go", "run.go", "", color.GreenString("Targeted Go version"))
5353
internal.AddHackedStringSlice(fs, "build-tags", color.GreenString("Build tags"))
5454

5555
internal.AddFlagAndBind(v, fs, fs.Duration, "timeout", "run.timeout", defaultTimeout,
56-
color.GreenString("Timeout for total work. If <= 0, the timeout is disabled"))
56+
color.GreenString("Timeout for total work. Disabled by default"))
5757

5858
internal.AddFlagAndBind(v, fs, fs.Bool, "tests", "run.tests", true, color.GreenString("Analyze tests (*_test.go)"))
5959

@@ -72,7 +72,7 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
7272
func setupOutputFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
7373
internal.AddFlagAndBind(v, fs, fs.String, "path-prefix", "output.path-prefix", "",
7474
color.GreenString("Path prefix to add to output"))
75-
internal.AddFlagAndBind(v, fs, fs.Bool, "show-stats", "output.show-stats", false, color.GreenString("Show statistics per linter"))
75+
internal.AddFlagAndBind(v, fs, fs.Bool, "show-stats", "output.show-stats", true, color.GreenString("Show statistics per linter"))
7676

7777
setupOutputFormatsFlagSet(v, fs)
7878
}

pkg/commands/run.go

+4-14
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import (
4343
"github.com/golangci/golangci-lint/pkg/timeutils"
4444
)
4545

46-
const defaultTimeout = time.Minute
46+
const defaultTimeout = 0 * time.Minute
4747

4848
const (
4949
// envFailOnWarnings value: "1"
@@ -161,6 +161,7 @@ func (c *runCommand) persistentPreRunE(cmd *cobra.Command, args []string) error
161161
}
162162

163163
if c.cfg.Run.Concurrency == 0 {
164+
// `runtime.GOMAXPROCS` defaults to the value of `runtime.NumCPU`.
164165
backup := runtime.GOMAXPROCS(0)
165166

166167
// Automatically set GOMAXPROCS to match Linux container CPU quota.
@@ -245,12 +246,11 @@ func (c *runCommand) execute(_ *cobra.Command, _ []string) {
245246
}
246247
}()
247248

248-
ctx := context.Background()
249+
ctx, cancel := context.WithCancel(context.Background())
249250
if c.cfg.Run.Timeout > 0 {
250-
var cancel context.CancelFunc
251251
ctx, cancel = context.WithTimeout(ctx, c.cfg.Run.Timeout)
252-
defer cancel()
253252
}
253+
defer cancel()
254254

255255
if needTrackResources {
256256
go watchResources(ctx, trackResourcesEndCh, c.log, c.debugf)
@@ -590,16 +590,6 @@ func setupRunPersistentFlags(fs *pflag.FlagSet, opts *runOptions) {
590590
fs.StringVar(&opts.TracePath, "trace-path", "", color.GreenString("Path to trace output file"))
591591
}
592592

593-
func getDefaultConcurrency() int {
594-
if os.Getenv(envHelpRun) == "1" {
595-
// Make stable concurrency for generating help documentation.
596-
const prettyConcurrency = 8
597-
return prettyConcurrency
598-
}
599-
600-
return runtime.NumCPU()
601-
}
602-
603593
func printMemStats(ms *runtime.MemStats, logger logutils.Log) {
604594
logger.Infof("Mem stats: alloc=%s total_alloc=%s sys=%s "+
605595
"heap_alloc=%s heap_sys=%s heap_idle=%s heap_released=%s heap_in_use=%s "+

pkg/config/config.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import (
1515
"golang.org/x/mod/modfile"
1616
)
1717

18+
// defaultGoVersion the value should be "oldstable" - 1.
19+
// If the current stable version is 1.24 then 1.23 - 1 = 1.22.
20+
const defaultGoVersion = "1.22"
21+
1822
// Config encapsulates the config data specified in the golangci-lint YAML config file.
1923
type Config struct {
2024
cfgDir string // Path to the directory containing golangci-lint config file.
@@ -93,7 +97,7 @@ func IsGoGreaterThanOrEqual(current, limit string) bool {
9397
}
9498

9599
func detectGoVersion(ctx context.Context) string {
96-
return cmp.Or(detectGoVersionFromGoMod(ctx), "1.17")
100+
return cmp.Or(detectGoVersionFromGoMod(ctx), defaultGoVersion)
97101
}
98102

99103
// detectGoVersionFromGoMod tries to get Go version from go.mod.

test/run_test.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func TestAutogeneratedNoIssues(t *testing.T) {
3737

3838
testshared.NewRunnerBuilder(t).
3939
WithConfig(cfg).
40+
WithArgs("--show-stats=false").
4041
WithTargetPath(testdataDir, "autogenerated").
4142
WithBinPath(binPath).
4243
Runner().
@@ -47,6 +48,7 @@ func TestAutogeneratedNoIssues(t *testing.T) {
4748
func TestEmptyDirRun(t *testing.T) {
4849
testshared.NewRunnerBuilder(t).
4950
WithEnviron("GO111MODULE=off").
51+
WithArgs("--show-stats=false").
5052
WithTargetPath(testdataDir, "nogofiles").
5153
Runner().
5254
Install().
@@ -69,6 +71,7 @@ func TestNotExistingDirRun(t *testing.T) {
6971

7072
func TestSymlinkLoop(t *testing.T) {
7173
testshared.NewRunnerBuilder(t).
74+
WithArgs("--show-stats=false").
7275
WithTargetPath(testdataDir, "symlink_loop", "...").
7376
Runner().
7477
Install().
@@ -120,7 +123,9 @@ func TestTestsAreLintedByDefault(t *testing.T) {
120123
func TestCgoOk(t *testing.T) {
121124
testshared.NewRunnerBuilder(t).
122125
WithNoConfig().
123-
WithArgs("--timeout=3m",
126+
WithArgs(
127+
"--timeout=3m",
128+
"--show-stats=false",
124129
"--enable-all",
125130
).
126131
WithTargetPath(testdataDir, "cgo").
@@ -358,7 +363,10 @@ func TestUnsafeOk(t *testing.T) {
358363

359364
testshared.NewRunnerBuilder(t).
360365
WithConfig(cfg).
361-
WithArgs("--enable-all").
366+
WithArgs(
367+
"--show-stats=false",
368+
"--enable-all",
369+
).
362370
WithTargetPath(testdataDir, "unsafe").
363371
WithBinPath(binPath).
364372
Runner().
@@ -371,7 +379,10 @@ func TestSortedResults(t *testing.T) {
371379

372380
testshared.NewRunnerBuilder(t).
373381
WithNoConfig().
374-
WithArgs("--output.text.print-issued-lines=false").
382+
WithArgs(
383+
"--show-stats=false",
384+
"--output.text.print-issued-lines=false",
385+
).
375386
WithTargetPath(testdataDir, "sort_results").
376387
WithBinPath(binPath).
377388
Runner().
@@ -385,7 +396,11 @@ func TestSortedResults(t *testing.T) {
385396
func TestIdentifierUsedOnlyInTests(t *testing.T) {
386397
testshared.NewRunnerBuilder(t).
387398
WithNoConfig().
388-
WithArgs("--disable-all", "-Eunused").
399+
WithArgs(
400+
"--show-stats=false",
401+
"--disable-all",
402+
"-Eunused",
403+
).
389404
WithTargetPath(testdataDir, "used_only_in_tests").
390405
Runner().
391406
Install().
@@ -395,6 +410,7 @@ func TestIdentifierUsedOnlyInTests(t *testing.T) {
395410

396411
func TestUnusedCheckExported(t *testing.T) {
397412
testshared.NewRunnerBuilder(t).
413+
WithArgs("--show-stats=false").
398414
WithConfigFile("testdata_etc/unused_exported/golangci.yml").
399415
WithTargetPath("testdata_etc/unused_exported/...").
400416
Runner().

test/testshared/integration/run.go

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func testOneSource(t *testing.T, log *logutils.StderrLog, binPath, sourcePath st
6363

6464
args := []string{
6565
"--disable-all",
66+
"--show-stats=false",
6667
"--output.json.path=stdout",
6768
"--max-same-issues=100",
6869
"--max-issues-per-linter=100",

0 commit comments

Comments
 (0)