Skip to content

Commit

Permalink
quit asap config, remove unused pkg info
Browse files Browse the repository at this point in the history
  • Loading branch information
chavacava committed Sep 17, 2023
1 parent 95acb88 commit 4de37b4
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions rule/unchecked-type-assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ const (
type UncheckedTypeAssertionRule struct {
sync.Mutex
acceptIgnoredAssertionResult bool
configured bool
}

func (u *UncheckedTypeAssertionRule) configure(arguments lint.Arguments) {
u.Lock()
defer u.Unlock()

if len(arguments) == 0 {
if len(arguments) == 0 || u.configured {
return
}

u.configured = true

args, ok := arguments[0].(map[string]any)
if !ok {
panic("Unable to get arguments. Expected object of key-value-pairs.")
Expand All @@ -52,14 +55,12 @@ func (u *UncheckedTypeAssertionRule) Apply(file *lint.File, args lint.Arguments)
var failures []lint.Failure

walker := &lintUnchekedTypeAssertion{
pkg: file.Pkg,
onFailure: func(failure lint.Failure) {
failures = append(failures, failure)
},
acceptIgnoredTypeAssertionResult: u.acceptIgnoredAssertionResult,
}

file.Pkg.TypeCheck()
ast.Walk(walker, file.AST)

return failures
Expand All @@ -71,7 +72,6 @@ func (*UncheckedTypeAssertionRule) Name() string {
}

type lintUnchekedTypeAssertion struct {
pkg *lint.Package
onFailure func(lint.Failure)
acceptIgnoredTypeAssertionResult bool
}
Expand All @@ -98,12 +98,10 @@ func (w *lintUnchekedTypeAssertion) requireNoTypeAssert(expr ast.Expr) {

func (w *lintUnchekedTypeAssertion) handleIfStmt(n *ast.IfStmt) {
ifCondition, ok := n.Cond.(*ast.BinaryExpr)
if !ok {
return
if ok {
w.requireNoTypeAssert(ifCondition.X)
w.requireNoTypeAssert(ifCondition.Y)
}

w.requireNoTypeAssert(ifCondition.X)
w.requireNoTypeAssert(ifCondition.Y)
}

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

0 comments on commit 4de37b4

Please sign in to comment.