Skip to content

Rename deadline option to timeout and mark deadline as deprecated #793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.tmpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
9 changes: 8 additions & 1 deletion test/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down