Skip to content

Commit 0cc87df

Browse files
titusjakajirfag
authored andcommitted
Rename deadline option to timeout and mark deadline as deprecated. (#793)
1 parent ee2e17f commit 0cc87df

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

.golangci.example.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ run:
77
concurrency: 4
88

99
# timeout for analysis, e.g. 30s, 5m, default is 1m
10-
deadline: 1m
10+
timeout: 1m
1111

1212
# exit code when at least one issue was found, default is 1
1313
issues-exit-code: 1

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test: build
3737

3838
test_race:
3939
go build -race -o golangci-lint ./cmd/golangci-lint
40-
GL_TEST_RUN=1 ./golangci-lint run -v --deadline=5m
40+
GL_TEST_RUN=1 ./golangci-lint run -v --timeout=5m
4141
.PHONY: test_race
4242

4343
test_linters:

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ We measure peak memory usage (RSS) by tracking of processes RSS every 5 ms.
337337
We compare golangci-lint and gometalinter in default mode, but explicitly enable all linters because of small differences in the default configuration.
338338
339339
```bash
340-
$ golangci-lint run --no-config --issues-exit-code=0 --deadline=30m \
340+
$ golangci-lint run --no-config --issues-exit-code=0 --timeout=30m \
341341
--disable-all --enable=deadcode --enable=gocyclo --enable=golint --enable=varcheck \
342342
--enable=structcheck --enable=maligned --enable=errcheck --enable=dupl --enable=ineffassign \
343343
--enable=interfacer --enable=unconvert --enable=goconst --enable=gosec --enable=megacheck
@@ -498,7 +498,7 @@ Flags:
498498
--print-linter-name Print linter name in issue line (default true)
499499
--issues-exit-code int Exit code when issues were found (default 1)
500500
--build-tags strings Build tags
501-
--deadline duration Deadline for total work (default 1m0s)
501+
--timeout duration Timeout for total work (default 1m0s)
502502
--tests Analyze tests (*_test.go) (default true)
503503
--print-resources-usage Print avg and max memory usage of golangci-lint and total time
504504
-c, --config PATH Read config from file path PATH
@@ -600,7 +600,7 @@ run:
600600
concurrency: 4
601601
602602
# timeout for analysis, e.g. 30s, 5m, default is 1m
603-
deadline: 1m
603+
timeout: 1m
604604
605605
# exit code when at least one issue was found, default is 1
606606
issues-exit-code: 1

README.tmpl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ We measure peak memory usage (RSS) by tracking of processes RSS every 5 ms.
299299
We compare golangci-lint and gometalinter in default mode, but explicitly enable all linters because of small differences in the default configuration.
300300

301301
```bash
302-
$ golangci-lint run --no-config --issues-exit-code=0 --deadline=30m \
302+
$ golangci-lint run --no-config --issues-exit-code=0 --timeout=30m \
303303
--disable-all --enable=deadcode --enable=gocyclo --enable=golint --enable=varcheck \
304304
--enable=structcheck --enable=maligned --enable=errcheck --enable=dupl --enable=ineffassign \
305305
--enable=interfacer --enable=unconvert --enable=goconst --enable=gosec --enable=megacheck

pkg/commands/run.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
8585
fs.IntVar(&rc.ExitCodeIfIssuesFound, "issues-exit-code",
8686
exitcodes.IssuesFound, wh("Exit code when issues were found"))
8787
fs.StringSliceVar(&rc.BuildTags, "build-tags", nil, wh("Build tags"))
88-
fs.DurationVar(&rc.Deadline, "deadline", time.Minute, wh("Deadline for total work"))
88+
fs.DurationVar(&rc.Timeout, "deadline", time.Minute, wh("Deadline for total work"))
89+
hideFlag("deadline")
90+
fs.DurationVar(&rc.Timeout, "timeout", time.Minute, wh("Timeout for total work"))
91+
8992
fs.BoolVar(&rc.AnalyzeTests, "tests", true, wh("Analyze tests (*_test.go)"))
9093
fs.BoolVar(&rc.PrintResourcesUsage, "print-resources-usage", false,
9194
wh("Print avg and max memory usage of golangci-lint and total time"))
@@ -387,7 +390,7 @@ func (e *Executor) executeRun(_ *cobra.Command, args []string) {
387390
}
388391
}()
389392

390-
ctx, cancel := context.WithTimeout(context.Background(), e.cfg.Run.Deadline)
393+
ctx, cancel := context.WithTimeout(context.Background(), e.cfg.Run.Timeout)
391394
defer cancel()
392395

393396
if needTrackResources {
@@ -411,7 +414,7 @@ func (e *Executor) executeRun(_ *cobra.Command, args []string) {
411414
func (e *Executor) setupExitCode(ctx context.Context) {
412415
if ctx.Err() != nil {
413416
e.exitCode = exitcodes.Timeout
414-
e.log.Errorf("Deadline exceeded: try increase it by passing --deadline option")
417+
e.log.Errorf("Timeout exceeded: try increase it by passing --timeout option")
415418
return
416419
}
417420

pkg/config/config.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,13 @@ type Run struct {
116116

117117
ExitCodeIfIssuesFound int `mapstructure:"issues-exit-code"`
118118
AnalyzeTests bool `mapstructure:"tests"`
119-
Deadline time.Duration
120-
PrintVersion bool
121119

120+
// Deprecated: Deadline exists for historical compatibility
121+
// and should not be used. To set run timeout use Timeout instead.
122+
Deadline time.Duration
123+
Timeout time.Duration
124+
125+
PrintVersion bool
122126
SkipFiles []string `mapstructure:"skip-files"`
123127
SkipDirs []string `mapstructure:"skip-dirs"`
124128
UseDefaultSkipDirs bool `mapstructure:"skip-dirs-use-default"`

test/run_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ func TestSymlinkLoop(t *testing.T) {
4444
func TestDeadline(t *testing.T) {
4545
testshared.NewLintRunner(t).Run("--deadline=1ms", getProjectRoot()).
4646
ExpectExitCode(exitcodes.Timeout).
47-
ExpectOutputContains(`Deadline exceeded: try increase it by passing --deadline option`)
47+
ExpectOutputContains(`Timeout exceeded: try increase it by passing --timeout option`).
48+
ExpectOutputContains(`Flag --deadline has been deprecated, flag will be removed soon, please, use .golangci.yml config`)
49+
}
50+
51+
func TestTimeout(t *testing.T) {
52+
testshared.NewLintRunner(t).Run("--timeout=1ms", getProjectRoot()).
53+
ExpectExitCode(exitcodes.Timeout).
54+
ExpectOutputContains(`Timeout exceeded: try increase it by passing --timeout option`)
4855
}
4956

5057
func TestTestsAreLintedByDefault(t *testing.T) {

0 commit comments

Comments
 (0)