1
0
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:
Oleksandr Redko 2023-11-06 12:01:38 +02:00 committed by GitHub
parent 29ba247979
commit ccae54e04e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 10 additions and 16 deletions

View File

@ -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]

View File

@ -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

View File

@ -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{

View File

@ -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
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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

View File

@ -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)