diff --git a/durationcheck.go b/durationcheck.go index 6eccd9c..61d4eb2 100644 --- a/durationcheck.go +++ b/durationcheck.go @@ -147,8 +147,7 @@ func isAcceptableNestedExpr(pass *analysis.Pass, n ast.Expr) bool { t := pass.TypesInfo.TypeOf(e) return !isDuration(t) case *ast.SelectorExpr: - t := pass.TypesInfo.TypeOf(e) - return !isDuration(t) + return isAcceptableNestedExpr(pass, e.X) && isAcceptableIdent(pass, e.Sel) } return false diff --git a/testdata/src/a/a.go b/testdata/src/a/a.go index b99a045..f805291 100644 --- a/testdata/src/a/a.go +++ b/testdata/src/a/a.go @@ -1,6 +1,7 @@ package a import ( + "b" "time" ) @@ -53,6 +54,10 @@ func validCases() { _ = time.Duration(ms.fieldA) * time.Second _ = time.Second * time.Duration(ms.fieldA) + + _ = b.SomeInt * time.Second + + _ = time.Second * b.SomeInt } func invalidCases() { @@ -80,6 +85,10 @@ func invalidCases() { _ = ms.fieldB * time.Second // want `Multiplication of durations` _ = time.Second * ms.fieldB // want `Multiplication of durations` + + _ = b.SomeDuration * time.Second // want `Multiplication of durations` + + _ = time.Second * b.SomeDuration // want `Multiplication of durations` } func someDuration() time.Duration { diff --git a/testdata/src/b/b.go b/testdata/src/b/b.go new file mode 100644 index 0000000..d7176d2 --- /dev/null +++ b/testdata/src/b/b.go @@ -0,0 +1,8 @@ +package b + +import "time" + +const ( + SomeInt = 10 + SomeDuration = 1 * time.Second +)