1
0
mirror of https://github.com/mgechev/revive.git synced 2025-11-29 22:28:23 +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
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 return ok
} }
ids := pick(funcLit.Body, selectIDs, nil) ids := pick(funcLit.Body, selectIDs)
for _, id := range ids { for _, id := range ids {
id := id.(*ast.Ident) id := id.(*ast.Ident)
_, isRangeID := w.rangeIDs[id.Obj] _, isRangeID := w.rangeIDs[id.Obj]

View File

@@ -88,7 +88,7 @@ func (w conditionVisitor) Visit(node ast.Node) ast.Visitor {
return false return false
} }
uses := pick(ifStmt.Cond, fselect, nil) uses := pick(ifStmt.Cond, fselect)
if len(uses) < 1 { if len(uses) < 1 {
return w return w

View File

@@ -97,7 +97,7 @@ func (w lintModifiesValRecRule) Visit(node ast.Node) ast.Visitor {
return false return false
} }
assignmentsToReceiver := pick(n.Body, fselect, nil) assignmentsToReceiver := pick(n.Body, fselect)
for _, assignment := range assignmentsToReceiver { for _, assignment := range assignmentsToReceiver {
w.onFailure(lint.Failure{ 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 // 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 { if len(nodes) < 1 {
return w return w
} }
// check if the right sub-expression does not contain a function call // 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 { if len(nodes) > 0 {
return w return w
} }

View File

@@ -195,5 +195,5 @@ func (lintUnconditionalRecursionRule) hasControlExit(node ast.Node) bool {
return false 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 return false
} }
_ = pick(n.Body, fselect, nil) _ = pick(n.Body, fselect)
for _, p := range n.Type.Params.List { for _, p := range n.Type.Params.List {
for _, n := range p.Names { 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 return isAnID && ident.Obj == recID.Obj
} }
refs2recID := pick(n.Body, fselect, nil) refs2recID := pick(n.Body, fselect)
if len(refs2recID) > 0 { if len(refs2recID) > 0 {
return nil // the receiver is referenced in the func body 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. // 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 // Nodes are selected by applying the fselect function
// f function is applied to each selected node before inserting it in the final result. func pick(n ast.Node, fselect func(n ast.Node) bool) []ast.Node {
// 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 {
var result []ast.Node var result []ast.Node
if n == nil { if n == nil {
return result return result
} }
if f == nil {
f = func(n ast.Node) []ast.Node { return []ast.Node{n} }
}
onSelect := func(n ast.Node) { onSelect := func(n ast.Node) {
result = append(result, f(n)...) result = append(result, n)
} }
p := picker{fselect: fselect, onSelect: onSelect} p := picker{fselect: fselect, onSelect: onSelect}
ast.Walk(p, n) ast.Walk(p, n)