From b39dbcd694baddce38eff2cb2aa86d4e4cf06753 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Sat, 20 Feb 2021 12:43:21 +0100 Subject: [PATCH] durationcheck: False positive when multiplying with int type struct field (#1744) --- go.mod | 2 +- go.sum | 4 ++-- test/testdata/durationcheck.go | 35 +++++++++++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 399026052237..c4b1b75b22b9 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 443cd749e1a8..5fa7b08d0b0a 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ github.com/bkielbasa/cyclop v1.2.0/go.mod h1:qOI0yy6A7dYC4Zgsa72Ppm9kONl0RoIlPbz github.com/bombsimon/wsl/v3 v3.1.0 h1:E5SRssoBgtVFPcYWUOFJEcgaySgdtTNYzsSKDOY7ss8= github.com/bombsimon/wsl/v3 v3.1.0/go.mod h1:st10JtZYLE4D5sC7b8xV4zTKZwAQjCH/Hy2Pm1FNZIc= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/charithe/durationcheck v0.0.3 h1:W+9cu38epH7otBF96pdhbFw5vLilsl1oseMOiOgex5E= -github.com/charithe/durationcheck v0.0.3/go.mod h1:0oCYOIgY8Om3hZxPedxKn0mzy0rneKTWJhRm+r6Gl20= +github.com/charithe/durationcheck v0.0.4 h1:lD3ud3KJ2DaoL80EZ768cSBv3DS8Xr7nNgN+kgW1tts= +github.com/charithe/durationcheck v0.0.4/go.mod h1:0oCYOIgY8Om3hZxPedxKn0mzy0rneKTWJhRm+r6Gl20= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= diff --git a/test/testdata/durationcheck.go b/test/testdata/durationcheck.go index 8fc6270bfee8..483f55c58488 100644 --- a/test/testdata/durationcheck.go +++ b/test/testdata/durationcheck.go @@ -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) }