Skip to content

Commit

Permalink
fix: False positive when multiplying with int type struct field
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Feb 17, 2021
1 parent 9c47715 commit 8d32966
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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.

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

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

func waitFor(someDuration time.Duration) {
type s struct {
d int
}

func durationcheckCase01() {
ss := s{10}
_ = time.Duration(ss.d) * time.Second
}

func durationcheckCase02() {
seconds := 10
fmt.Print(time.Duration(seconds) * time.Second)
}

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

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

0 comments on commit 8d32966

Please sign in to comment.