forked from golangci/golangci-lint
/
durationcheck.go
38 lines (31 loc) · 905 Bytes
/
durationcheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//golangcitest:args -Edurationcheck
package testdata
import (
"fmt"
"time"
)
type durationCheckData struct {
i int
d time.Duration
}
func durationcheckCase01() {
dcd := durationCheckData{i: 10}
_ = time.Duration(dcd.i) * time.Second
}
func durationcheckCase02() {
dcd := durationCheckData{d: 10 * time.Second}
_ = dcd.d * time.Second // ERROR "Multiplication of durations: `dcd.d \\* time.Second`"
}
func durationcheckCase03() {
seconds := 10
fmt.Print(time.Duration(seconds) * time.Second)
}
func durationcheckCase04(someDuration time.Duration) {
timeToWait := someDuration * time.Second // ERROR "Multiplication of durations: `someDuration \\* time.Second`"
time.Sleep(timeToWait)
}
func durationcheckCase05() {
someDuration := 2 * time.Second
timeToWait := someDuration * time.Second // ERROR "Multiplication of durations: `someDuration \\* time.Second`"
time.Sleep(timeToWait)
}