Skip to content

Commit b0b2dc6

Browse files
ldezSergey Vilgelm
and
Sergey Vilgelm
authored
feat: add durationcheck linter. (#1734)
Co-authored-by: Sergey Vilgelm <sergey.vilgelm@ibm.com>
1 parent 35b6f35 commit b0b2dc6

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/ashanbrown/forbidigo v1.1.0
1111
github.com/ashanbrown/makezero v0.0.0-20201205152432-7b7cdbb3025a
1212
github.com/bombsimon/wsl/v3 v3.1.0
13+
github.com/charithe/durationcheck v0.0.3
1314
github.com/daixiang0/gci v0.2.8
1415
github.com/denis-tingajkin/go-header v0.4.2
1516
github.com/esimonov/ifshort v1.0.1

go.sum

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/durationcheck.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package golinters
2+
3+
import (
4+
"github.com/charithe/durationcheck"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+
)
9+
10+
func NewDurationCheck() *goanalysis.Linter {
11+
a := durationcheck.Analyzer
12+
13+
return goanalysis.NewLinter(a.Name, a.Doc, []*analysis.Analyzer{a}, nil).
14+
WithLoadMode(goanalysis.LoadModeTypesInfo)
15+
}

pkg/lint/lintersdb/manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
357357
linter.NewConfig(golinters.NewRevive(reviveCfg)).
358358
WithPresets(linter.PresetStyle).
359359
WithURL("https://github.com/mgechev/revive"),
360+
linter.NewConfig(golinters.NewDurationCheck()).
361+
WithPresets(linter.PresetBugs).
362+
WithLoadForGoAnalysis().
363+
WithURL("https://github.com/charithe/durationcheck"),
360364

361365
// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
362366
linter.NewConfig(golinters.NewNoLintLint()).

test/testdata/durationcheck.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//args: -Edurationcheck
2+
package testdata
3+
4+
import "time"
5+
6+
func waitFor(someDuration time.Duration) {
7+
timeToWait := someDuration * time.Second // ERROR "Multiplication of durations: `someDuration \\* time.Second` "
8+
time.Sleep(timeToWait)
9+
}

0 commit comments

Comments
 (0)