Skip to content

Commit

Permalink
feat: add durationcheck linter. (#1734)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergey Vilgelm <sergey.vilgelm@ibm.com>
  • Loading branch information
ldez and Sergey Vilgelm authored Feb 14, 2021
1 parent 35b6f35 commit b0b2dc6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/ashanbrown/forbidigo v1.1.0
github.com/ashanbrown/makezero v0.0.0-20201205152432-7b7cdbb3025a
github.com/bombsimon/wsl/v3 v3.1.0
github.com/charithe/durationcheck v0.0.3
github.com/daixiang0/gci v0.2.8
github.com/denis-tingajkin/go-header v0.4.2
github.com/esimonov/ifshort v1.0.1
Expand Down
3 changes: 3 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions pkg/golinters/durationcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package golinters

import (
"github.com/charithe/durationcheck"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

func NewDurationCheck() *goanalysis.Linter {
a := durationcheck.Analyzer

return goanalysis.NewLinter(a.Name, a.Doc, []*analysis.Analyzer{a}, nil).
WithLoadMode(goanalysis.LoadModeTypesInfo)
}
4 changes: 4 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
linter.NewConfig(golinters.NewRevive(reviveCfg)).
WithPresets(linter.PresetStyle).
WithURL("https://github.com/mgechev/revive"),
linter.NewConfig(golinters.NewDurationCheck()).
WithPresets(linter.PresetBugs).
WithLoadForGoAnalysis().
WithURL("https://github.com/charithe/durationcheck"),

// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
linter.NewConfig(golinters.NewNoLintLint()).
Expand Down
9 changes: 9 additions & 0 deletions test/testdata/durationcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//args: -Edurationcheck
package testdata

import "time"

func waitFor(someDuration time.Duration) {
timeToWait := someDuration * time.Second // ERROR "Multiplication of durations: `someDuration \\* time.Second` "
time.Sleep(timeToWait)
}

0 comments on commit b0b2dc6

Please sign in to comment.