From f72ffdb12636e2626a1086c9e0220a65aab79b40 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Sat, 4 Nov 2023 11:57:06 +0200 Subject: [PATCH] refactor: remove unused parameter from pick function --- rule/datarace.go | 2 +- rule/flag-param.go | 2 +- rule/modifies-value-receiver.go | 2 +- rule/optimize-operands-order.go | 4 ++-- rule/unconditional-recursion.go | 2 +- rule/unused-param.go | 2 +- rule/unused-receiver.go | 2 +- rule/utils.go | 10 ++-------- 8 files changed, 10 insertions(+), 16 deletions(-) diff --git a/rule/datarace.go b/rule/datarace.go index c8754ea65..39e96696a 100644 --- a/rule/datarace.go +++ b/rule/datarace.go @@ -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] diff --git a/rule/flag-param.go b/rule/flag-param.go index 19a05f9fe..f9bfb712c 100644 --- a/rule/flag-param.go +++ b/rule/flag-param.go @@ -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 diff --git a/rule/modifies-value-receiver.go b/rule/modifies-value-receiver.go index 34e651557..ae260a9ad 100644 --- a/rule/modifies-value-receiver.go +++ b/rule/modifies-value-receiver.go @@ -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{ diff --git a/rule/optimize-operands-order.go b/rule/optimize-operands-order.go index 88928bb98..841bde56c 100644 --- a/rule/optimize-operands-order.go +++ b/rule/optimize-operands-order.go @@ -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 } diff --git a/rule/unconditional-recursion.go b/rule/unconditional-recursion.go index 7e73b72d4..9ac2648cd 100644 --- a/rule/unconditional-recursion.go +++ b/rule/unconditional-recursion.go @@ -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 } diff --git a/rule/unused-param.go b/rule/unused-param.go index 1f736184f..63eab3705 100644 --- a/rule/unused-param.go +++ b/rule/unused-param.go @@ -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 { diff --git a/rule/unused-receiver.go b/rule/unused-receiver.go index 691c1fb58..715dba338 100644 --- a/rule/unused-receiver.go +++ b/rule/unused-receiver.go @@ -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 diff --git a/rule/utils.go b/rule/utils.go index 9e7f13ee1..5778e7696 100644 --- a/rule/utils.go +++ b/rule/utils.go @@ -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)