Skip to content

Commit

Permalink
durationcheck: False positive when multiplying with int type struct f…
Browse files Browse the repository at this point in the history
…ield (#1744)
  • Loading branch information
ldez authored Feb 20, 2021
1 parent ea5f479 commit b39dbcd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/ashanbrown/makezero v0.0.0-20201205152432-7b7cdbb3025a
github.com/bkielbasa/cyclop v1.2.0
github.com/bombsimon/wsl/v3 v3.1.0
github.com/charithe/durationcheck v0.0.3
github.com/charithe/durationcheck v0.0.4
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
4 changes: 2 additions & 2 deletions go.sum

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

35 changes: 32 additions & 3 deletions test/testdata/durationcheck.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
//args: -Edurationcheck
package testdata

import "time"
import (
"fmt"
"time"
)

func waitFor(someDuration time.Duration) {
timeToWait := someDuration * time.Second // ERROR "Multiplication of durations: `someDuration \\* time.Second` "
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)
}

0 comments on commit b39dbcd

Please sign in to comment.