Skip to content

Commit b39dbcd

Browse files
authored
durationcheck: False positive when multiplying with int type struct field (#1744)
1 parent ea5f479 commit b39dbcd

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/ashanbrown/makezero v0.0.0-20201205152432-7b7cdbb3025a
1313
github.com/bkielbasa/cyclop v1.2.0
1414
github.com/bombsimon/wsl/v3 v3.1.0
15-
github.com/charithe/durationcheck v0.0.3
15+
github.com/charithe/durationcheck v0.0.4
1616
github.com/daixiang0/gci v0.2.8
1717
github.com/denis-tingajkin/go-header v0.4.2
1818
github.com/esimonov/ifshort v1.0.1

go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/testdata/durationcheck.go

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
11
//args: -Edurationcheck
22
package testdata
33

4-
import "time"
4+
import (
5+
"fmt"
6+
"time"
7+
)
58

6-
func waitFor(someDuration time.Duration) {
7-
timeToWait := someDuration * time.Second // ERROR "Multiplication of durations: `someDuration \\* time.Second` "
9+
type durationCheckData struct {
10+
i int
11+
d time.Duration
12+
}
13+
14+
func durationcheckCase01() {
15+
dcd := durationCheckData{i: 10}
16+
_ = time.Duration(dcd.i) * time.Second
17+
}
18+
19+
func durationcheckCase02() {
20+
dcd := durationCheckData{d: 10 * time.Second}
21+
_ = dcd.d * time.Second // ERROR "Multiplication of durations: `dcd.d \\* time.Second`"
22+
}
23+
24+
func durationcheckCase03() {
25+
seconds := 10
26+
fmt.Print(time.Duration(seconds) * time.Second)
27+
}
28+
29+
func durationcheckCase04(someDuration time.Duration) {
30+
timeToWait := someDuration * time.Second // ERROR "Multiplication of durations: `someDuration \\* time.Second`"
31+
time.Sleep(timeToWait)
32+
}
33+
34+
func durationcheckCase05() {
35+
someDuration := 2 * time.Second
36+
timeToWait := someDuration * time.Second // ERROR "Multiplication of durations: `someDuration \\* time.Second`"
837
time.Sleep(timeToWait)
938
}

0 commit comments

Comments
 (0)