mirror of
https://github.com/mgechev/revive.git
synced 2024-11-24 08:32:22 +02:00
refactor: remove unused parameter from pick function (#932)
This commit is contained in:
parent
29ba247979
commit
ccae54e04e
@ -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]
|
||||
|
@ -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
|
||||
|
@ -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{
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user