Skip to content

Commit 7dffe3c

Browse files
authored
quit config asap, remove unused pkg info (#896)
1 parent 95acb88 commit 7dffe3c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

rule/unchecked-type-assertion.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ const (
1717
type UncheckedTypeAssertionRule struct {
1818
sync.Mutex
1919
acceptIgnoredAssertionResult bool
20+
configured bool
2021
}
2122

2223
func (u *UncheckedTypeAssertionRule) configure(arguments lint.Arguments) {
2324
u.Lock()
2425
defer u.Unlock()
2526

26-
if len(arguments) == 0 {
27+
if len(arguments) == 0 || u.configured {
2728
return
2829
}
2930

31+
u.configured = true
32+
3033
args, ok := arguments[0].(map[string]any)
3134
if !ok {
3235
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)
5255
var failures []lint.Failure
5356

5457
walker := &lintUnchekedTypeAssertion{
55-
pkg: file.Pkg,
5658
onFailure: func(failure lint.Failure) {
5759
failures = append(failures, failure)
5860
},
5961
acceptIgnoredTypeAssertionResult: u.acceptIgnoredAssertionResult,
6062
}
6163

62-
file.Pkg.TypeCheck()
6364
ast.Walk(walker, file.AST)
6465

6566
return failures
@@ -71,7 +72,6 @@ func (*UncheckedTypeAssertionRule) Name() string {
7172
}
7273

7374
type lintUnchekedTypeAssertion struct {
74-
pkg *lint.Package
7575
onFailure func(lint.Failure)
7676
acceptIgnoredTypeAssertionResult bool
7777
}
@@ -98,12 +98,10 @@ func (w *lintUnchekedTypeAssertion) requireNoTypeAssert(expr ast.Expr) {
9898

9999
func (w *lintUnchekedTypeAssertion) handleIfStmt(n *ast.IfStmt) {
100100
ifCondition, ok := n.Cond.(*ast.BinaryExpr)
101-
if !ok {
102-
return
101+
if ok {
102+
w.requireNoTypeAssert(ifCondition.X)
103+
w.requireNoTypeAssert(ifCondition.Y)
103104
}
104-
105-
w.requireNoTypeAssert(ifCondition.X)
106-
w.requireNoTypeAssert(ifCondition.Y)
107105
}
108106

109107
func (w *lintUnchekedTypeAssertion) requireBinaryExpressionWithoutTypeAssertion(expr ast.Expr) {

0 commit comments

Comments
 (0)