Skip to content

Commit

Permalink
Rename deadline option to timeout and mark deadline as deprecated. (#793
Browse files Browse the repository at this point in the history
)
  • Loading branch information
titusjaka authored and jirfag committed Oct 8, 2019
1 parent ee2e17f commit 0cc87df
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 12 deletions.
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

This comment has been minimized.

Copy link
@therealslimhsiehdy

therealslimhsiehdy Oct 14, 2019

Is it intended that deadline is still supported and backwards compatible? If so, the value from deadline gets replaced when reading timeout flag seen here.

// 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

0 comments on commit 0cc87df

Please sign in to comment.