Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quit asap config, remove unused pkg info #896

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading