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

refactor: remove unused parameter from pick function #932

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion rule/datarace.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (w lintFunctionForDataRaces) Visit(node ast.Node) ast.Visitor {
return ok
}

ids := pick(funcLit.Body, selectIDs, nil)
ids := pick(funcLit.Body, selectIDs)
for _, id := range ids {
id := id.(*ast.Ident)
_, isRangeID := w.rangeIDs[id.Obj]
Expand Down
2 changes: 1 addition & 1 deletion rule/flag-param.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (w conditionVisitor) Visit(node ast.Node) ast.Visitor {
return false
}

uses := pick(ifStmt.Cond, fselect, nil)
uses := pick(ifStmt.Cond, fselect)

if len(uses) < 1 {
return w
Expand Down
2 changes: 1 addition & 1 deletion rule/modifies-value-receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (w lintModifiesValRecRule) Visit(node ast.Node) ast.Visitor {
return false
}

assignmentsToReceiver := pick(n.Body, fselect, nil)
assignmentsToReceiver := pick(n.Body, fselect)

for _, assignment := range assignmentsToReceiver {
w.onFailure(lint.Failure{
Expand Down
4 changes: 2 additions & 2 deletions rule/optimize-operands-order.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ func (w lintOptimizeOperandsOrderlExpr) Visit(node ast.Node) ast.Visitor {
}

// check if the left sub-expression contains a function call
nodes := pick(binExpr.X, isCaller, nil)
nodes := pick(binExpr.X, isCaller)
if len(nodes) < 1 {
return w
}

// check if the right sub-expression does not contain a function call
nodes = pick(binExpr.Y, isCaller, nil)
nodes = pick(binExpr.Y, isCaller)
if len(nodes) > 0 {
return w
}
Expand Down
2 changes: 1 addition & 1 deletion rule/unconditional-recursion.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,5 @@ func (lintUnconditionalRecursionRule) hasControlExit(node ast.Node) bool {
return false
}

return len(pick(node, isExit, nil)) != 0
return len(pick(node, isExit)) != 0
}
2 changes: 1 addition & 1 deletion rule/unused-param.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (w lintUnusedParamRule) Visit(node ast.Node) ast.Visitor {

return false
}
_ = pick(n.Body, fselect, nil)
_ = pick(n.Body, fselect)

for _, p := range n.Type.Params.List {
for _, n := range p.Names {
Expand Down
2 changes: 1 addition & 1 deletion rule/unused-receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (w lintUnusedReceiverRule) Visit(node ast.Node) ast.Visitor {

return isAnID && ident.Obj == recID.Obj
}
refs2recID := pick(n.Body, fselect, nil)
refs2recID := pick(n.Body, fselect)

if len(refs2recID) > 0 {
return nil // the receiver is referenced in the func body
Expand Down
10 changes: 2 additions & 8 deletions rule/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,15 @@ func srcLine(src []byte, p token.Position) string {

// pick yields a list of nodes by picking them from a sub-ast with root node n.
// Nodes are selected by applying the fselect function
// f function is applied to each selected node before inserting it in the final result.
// If f==nil then it defaults to the identity function (ie it returns the node itself)
func pick(n ast.Node, fselect func(n ast.Node) bool, f func(n ast.Node) []ast.Node) []ast.Node {
func pick(n ast.Node, fselect func(n ast.Node) bool) []ast.Node {
var result []ast.Node

if n == nil {
return result
}

if f == nil {
f = func(n ast.Node) []ast.Node { return []ast.Node{n} }
}

onSelect := func(n ast.Node) {
result = append(result, f(n)...)
result = append(result, n)
}
p := picker{fselect: fselect, onSelect: onSelect}
ast.Walk(p, n)
Expand Down
Loading