File tree 2 files changed +11
-0
lines changed 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,8 @@ func isUnacceptableExpr(pass *analysis.Pass, expr ast.Expr) bool {
98
98
return ! isAcceptableNestedExpr (pass , e )
99
99
case * ast.ParenExpr :
100
100
return ! isAcceptableNestedExpr (pass , e )
101
+ case * ast.IndexExpr :
102
+ return ! isAcceptableNestedExpr (pass , e )
101
103
default :
102
104
return true
103
105
}
@@ -156,6 +158,9 @@ func isAcceptableNestedExpr(pass *analysis.Pass, n ast.Expr) bool {
156
158
return isAcceptableNestedExpr (pass , e .X )
157
159
case * ast.ParenExpr :
158
160
return isAcceptableNestedExpr (pass , e .X )
161
+ case * ast.IndexExpr :
162
+ t := pass .TypesInfo .TypeOf (e )
163
+ return ! isDuration (t )
159
164
default :
160
165
return false
161
166
}
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ type myStruct struct {
19
19
func validCases () {
20
20
y := 10
21
21
ms := myStruct {fieldA : 10 , fieldB : 10 * time .Second , fieldC : func (v int ) * int { return & v }(10 )}
22
+ intArr := []int {1 }
22
23
23
24
_ = time .Second * 30
24
25
@@ -71,11 +72,14 @@ func validCases() {
71
72
_ = b .SomeInt * time .Second
72
73
73
74
_ = time .Second * b .SomeInt
75
+
76
+ _ = time .Duration (intArr [0 ]) * time .Second
74
77
}
75
78
76
79
func invalidCases () {
77
80
x := 30 * time .Second
78
81
ms := myStruct {fieldA : 10 , fieldB : 10 * time .Second }
82
+ tdArr := []time.Duration {1 }
79
83
80
84
_ = x * time .Second // want `Multiplication of durations`
81
85
@@ -106,6 +110,8 @@ func invalidCases() {
106
110
_ = b .SomeDuration * time .Second // want `Multiplication of durations`
107
111
108
112
_ = time .Second * b .SomeDuration // want `Multiplication of durations`
113
+
114
+ _ = time .Duration (tdArr [0 ]) * time .Second // want `Multiplication of durations`
109
115
}
110
116
111
117
func someDuration () time.Duration {
You can’t perform that action at this time.
0 commit comments