aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGautham Goli2017-06-01 00:52:49 +0530
committerGautham Goli2017-06-08 19:50:04 +0530
commit134da5b8c266d0e5f07a1f79bff233f372c7ef30 (patch)
treee1307b8eec6e7b0476943e2fa521714f95339146
parentb6e1dde7c9b2de2cfee83a6e25833fb359686b43 (diff)
downloadbrew-134da5b8c266d0e5f07a1f79bff233f372c7ef30.tar.bz2
Add methods in FormulaCop to find block nodes
-rw-r--r--Library/Homebrew/rubocops/extend/formula_cop.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb
index 75a3e72d5..6bb406c05 100644
--- a/Library/Homebrew/rubocops/extend/formula_cop.rb
+++ b/Library/Homebrew/rubocops/extend/formula_cop.rb
@@ -167,12 +167,18 @@ module RuboCop
nil
end
- # Returns an array of block nodes named block_name inside node
+ # Returns an array of block nodes of depth first order named block_name below node
def find_blocks(node, block_name)
return if node.nil?
node.each_child_node(:block).select { |block_node| block_name == block_node.method_name }
end
+ # Returns an array of block nodes of any depth below node in AST
+ def find_all_blocks(node, block_name)
+ return if node.nil?
+ node.each_descendant(:block).select { |block_node| block_name == block_node.method_name}
+ end
+
# Returns a method definition node with method_name
def find_method_def(node, method_name)
return if node.nil?
@@ -250,7 +256,7 @@ module RuboCop
# Returns the array of arguments of the method_node
def parameters(method_node)
- return unless method_node.send_type?
+ return unless method_node.send_type? || method_node.block_type?
method_node.method_args
end