golangci-lint/test/testdata/durationcheck.go
Ludovic Fernandez b39dbcd694
Some checks failed
Extra / Vulnerability scanner (push) Failing after 33s
CI / go-mod (push) Failing after 43s
CI / golangci-lint (push) Failing after 1m0s
CI / tests-on-windows (push) Has been skipped
CI / tests-on-macos (push) Has been skipped
CI / tests-on-unix (1.14) (push) Has been skipped
CI / tests-on-unix (1.15) (push) Has been skipped
CI / tests-on-unix (1.16) (push) Has been skipped
CI / check_generated (push) Has been skipped
Release a tag / release (push) Failing after 1m10s
Release a tag / docker-release (map[Dockerfile:build/Dockerfile.alpine]) (push) Has been skipped
Release a tag / docker-release (map[Dockerfile:build/Dockerfile]) (push) Has been skipped
durationcheck: False positive when multiplying with int type struct field (#1744)
2021-02-20 12:43:21 +01:00

39 lines
893 B
Go

//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)
}