From 0cc87df732aaf1d5ad9ce9ca538d38d916918b36 Mon Sep 17 00:00:00 2001 From: Denis Titusov Date: Tue, 8 Oct 2019 09:37:54 +0300 Subject: [PATCH] Rename deadline option to timeout and mark deadline as deprecated. (#793) --- .golangci.example.yml | 2 +- Makefile | 2 +- README.md | 6 +++--- README.tmpl.md | 2 +- pkg/commands/run.go | 9 ++++++--- pkg/config/config.go | 8 ++++++-- test/run_test.go | 9 ++++++++- 7 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.golangci.example.yml b/.golangci.example.yml index 7a19b12f5d72..2d3feb9e0bd5 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -7,7 +7,7 @@ run: concurrency: 4 # timeout for analysis, e.g. 30s, 5m, default is 1m - deadline: 1m + timeout: 1m # exit code when at least one issue was found, default is 1 issues-exit-code: 1 diff --git a/Makefile b/Makefile index 548c75c888f2..365751a9ef17 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ test: build test_race: go build -race -o golangci-lint ./cmd/golangci-lint - GL_TEST_RUN=1 ./golangci-lint run -v --deadline=5m + GL_TEST_RUN=1 ./golangci-lint run -v --timeout=5m .PHONY: test_race test_linters: diff --git a/README.md b/README.md index 1f86213d7db5..7241958b4411 100644 --- a/README.md +++ b/README.md @@ -337,7 +337,7 @@ We measure peak memory usage (RSS) by tracking of processes RSS every 5 ms. We compare golangci-lint and gometalinter in default mode, but explicitly enable all linters because of small differences in the default configuration. ```bash -$ golangci-lint run --no-config --issues-exit-code=0 --deadline=30m \ +$ golangci-lint run --no-config --issues-exit-code=0 --timeout=30m \ --disable-all --enable=deadcode --enable=gocyclo --enable=golint --enable=varcheck \ --enable=structcheck --enable=maligned --enable=errcheck --enable=dupl --enable=ineffassign \ --enable=interfacer --enable=unconvert --enable=goconst --enable=gosec --enable=megacheck @@ -498,7 +498,7 @@ Flags: --print-linter-name Print linter name in issue line (default true) --issues-exit-code int Exit code when issues were found (default 1) --build-tags strings Build tags - --deadline duration Deadline for total work (default 1m0s) + --timeout duration Timeout for total work (default 1m0s) --tests Analyze tests (*_test.go) (default true) --print-resources-usage Print avg and max memory usage of golangci-lint and total time -c, --config PATH Read config from file path PATH @@ -600,7 +600,7 @@ run: concurrency: 4 # timeout for analysis, e.g. 30s, 5m, default is 1m - deadline: 1m + timeout: 1m # exit code when at least one issue was found, default is 1 issues-exit-code: 1 diff --git a/README.tmpl.md b/README.tmpl.md index 42de35173195..0f47ff13cd8e 100644 --- a/README.tmpl.md +++ b/README.tmpl.md @@ -299,7 +299,7 @@ We measure peak memory usage (RSS) by tracking of processes RSS every 5 ms. We compare golangci-lint and gometalinter in default mode, but explicitly enable all linters because of small differences in the default configuration. ```bash -$ golangci-lint run --no-config --issues-exit-code=0 --deadline=30m \ +$ golangci-lint run --no-config --issues-exit-code=0 --timeout=30m \ --disable-all --enable=deadcode --enable=gocyclo --enable=golint --enable=varcheck \ --enable=structcheck --enable=maligned --enable=errcheck --enable=dupl --enable=ineffassign \ --enable=interfacer --enable=unconvert --enable=goconst --enable=gosec --enable=megacheck diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 1a773a2ef34a..7e5f429d1b8d 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -85,7 +85,10 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is fs.IntVar(&rc.ExitCodeIfIssuesFound, "issues-exit-code", exitcodes.IssuesFound, wh("Exit code when issues were found")) fs.StringSliceVar(&rc.BuildTags, "build-tags", nil, wh("Build tags")) - fs.DurationVar(&rc.Deadline, "deadline", time.Minute, wh("Deadline for total work")) + fs.DurationVar(&rc.Timeout, "deadline", time.Minute, wh("Deadline for total work")) + hideFlag("deadline") + fs.DurationVar(&rc.Timeout, "timeout", time.Minute, wh("Timeout for total work")) + fs.BoolVar(&rc.AnalyzeTests, "tests", true, wh("Analyze tests (*_test.go)")) fs.BoolVar(&rc.PrintResourcesUsage, "print-resources-usage", false, 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) { } }() - ctx, cancel := context.WithTimeout(context.Background(), e.cfg.Run.Deadline) + ctx, cancel := context.WithTimeout(context.Background(), e.cfg.Run.Timeout) defer cancel() if needTrackResources { @@ -411,7 +414,7 @@ func (e *Executor) executeRun(_ *cobra.Command, args []string) { func (e *Executor) setupExitCode(ctx context.Context) { if ctx.Err() != nil { e.exitCode = exitcodes.Timeout - e.log.Errorf("Deadline exceeded: try increase it by passing --deadline option") + e.log.Errorf("Timeout exceeded: try increase it by passing --timeout option") return } diff --git a/pkg/config/config.go b/pkg/config/config.go index 206a4341c86d..90b0669683fe 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -116,9 +116,13 @@ type Run struct { ExitCodeIfIssuesFound int `mapstructure:"issues-exit-code"` AnalyzeTests bool `mapstructure:"tests"` - Deadline time.Duration - PrintVersion bool + // Deprecated: Deadline exists for historical compatibility + // and should not be used. To set run timeout use Timeout instead. + Deadline time.Duration + Timeout time.Duration + + PrintVersion bool SkipFiles []string `mapstructure:"skip-files"` SkipDirs []string `mapstructure:"skip-dirs"` UseDefaultSkipDirs bool `mapstructure:"skip-dirs-use-default"` diff --git a/test/run_test.go b/test/run_test.go index 30fe6a0925f7..4c4cf71aab06 100644 --- a/test/run_test.go +++ b/test/run_test.go @@ -44,7 +44,14 @@ func TestSymlinkLoop(t *testing.T) { func TestDeadline(t *testing.T) { testshared.NewLintRunner(t).Run("--deadline=1ms", getProjectRoot()). ExpectExitCode(exitcodes.Timeout). - ExpectOutputContains(`Deadline exceeded: try increase it by passing --deadline option`) + ExpectOutputContains(`Timeout exceeded: try increase it by passing --timeout option`). + ExpectOutputContains(`Flag --deadline has been deprecated, flag will be removed soon, please, use .golangci.yml config`) +} + +func TestTimeout(t *testing.T) { + testshared.NewLintRunner(t).Run("--timeout=1ms", getProjectRoot()). + ExpectExitCode(exitcodes.Timeout). + ExpectOutputContains(`Timeout exceeded: try increase it by passing --timeout option`) } func TestTestsAreLintedByDefault(t *testing.T) {