@@ -17,16 +17,19 @@ const (
17
17
type UncheckedTypeAssertionRule struct {
18
18
sync.Mutex
19
19
acceptIgnoredAssertionResult bool
20
+ configured bool
20
21
}
21
22
22
23
func (u * UncheckedTypeAssertionRule ) configure (arguments lint.Arguments ) {
23
24
u .Lock ()
24
25
defer u .Unlock ()
25
26
26
- if len (arguments ) == 0 {
27
+ if len (arguments ) == 0 || u . configured {
27
28
return
28
29
}
29
30
31
+ u .configured = true
32
+
30
33
args , ok := arguments [0 ].(map [string ]any )
31
34
if ! ok {
32
35
panic ("Unable to get arguments. Expected object of key-value-pairs." )
@@ -52,14 +55,12 @@ func (u *UncheckedTypeAssertionRule) Apply(file *lint.File, args lint.Arguments)
52
55
var failures []lint.Failure
53
56
54
57
walker := & lintUnchekedTypeAssertion {
55
- pkg : file .Pkg ,
56
58
onFailure : func (failure lint.Failure ) {
57
59
failures = append (failures , failure )
58
60
},
59
61
acceptIgnoredTypeAssertionResult : u .acceptIgnoredAssertionResult ,
60
62
}
61
63
62
- file .Pkg .TypeCheck ()
63
64
ast .Walk (walker , file .AST )
64
65
65
66
return failures
@@ -71,7 +72,6 @@ func (*UncheckedTypeAssertionRule) Name() string {
71
72
}
72
73
73
74
type lintUnchekedTypeAssertion struct {
74
- pkg * lint.Package
75
75
onFailure func (lint.Failure )
76
76
acceptIgnoredTypeAssertionResult bool
77
77
}
@@ -98,12 +98,10 @@ func (w *lintUnchekedTypeAssertion) requireNoTypeAssert(expr ast.Expr) {
98
98
99
99
func (w * lintUnchekedTypeAssertion ) handleIfStmt (n * ast.IfStmt ) {
100
100
ifCondition , ok := n .Cond .(* ast.BinaryExpr )
101
- if ! ok {
102
- return
101
+ if ok {
102
+ w .requireNoTypeAssert (ifCondition .X )
103
+ w .requireNoTypeAssert (ifCondition .Y )
103
104
}
104
-
105
- w .requireNoTypeAssert (ifCondition .X )
106
- w .requireNoTypeAssert (ifCondition .Y )
107
105
}
108
106
109
107
func (w * lintUnchekedTypeAssertion ) requireBinaryExpressionWithoutTypeAssertion (expr ast.Expr ) {
0 commit comments