mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
durationcheck: False positive when multiplying with int type struct field (#1744)
This commit is contained in:
parent
ea5f479087
commit
b39dbcd694
3 changed files with 35 additions and 6 deletions
35
test/testdata/durationcheck.go
vendored
35
test/testdata/durationcheck.go
vendored
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue