diff options
| author | Gautham Goli | 2017-07-31 14:30:37 +0530 | 
|---|---|---|
| committer | Gautham Goli | 2017-08-06 18:36:09 +0530 | 
| commit | b5da76e28d0a01d8e07076f8bba6cd2733597d6c (patch) | |
| tree | 101c24a3ed583da37a13f793e6bd9ca38cfd2b46 /Library/Homebrew/rubocops/extend/formula_cop.rb | |
| parent | bc2bcef1ba084e271ecdfd523a96e6db477e6475 (diff) | |
| download | brew-b5da76e28d0a01d8e07076f8bba6cd2733597d6c.tar.bz2 | |
audit: Port FileUtils, inreplace audit rules in audit_lines to rubocop
Diffstat (limited to 'Library/Homebrew/rubocops/extend/formula_cop.rb')
| -rw-r--r-- | Library/Homebrew/rubocops/extend/formula_cop.rb | 18 | 
1 files changed, 14 insertions, 4 deletions
diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index e7a23ecae..f8864538a 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -85,9 +85,13 @@ module RuboCop        end        # Returns an array of method call nodes matching method_name in every descendant of node -      def find_every_method_call_by_name(node, method_name) +      # Returns every method call if no method_name is passed +      def find_every_method_call_by_name(node, method_name = nil)          return if node.nil? -        node.each_descendant(:send).select { |method_node| method_name == method_node.method_name } +        node.each_descendant(:send).select do |method_node| +          method_name.nil? || +            method_name == method_node.method_name +        end        end        # Given a method_name and arguments, yields to a block with @@ -107,7 +111,7 @@ module RuboCop        def find_instance_method_call(node, instance, method_name)          methods = find_every_method_call_by_name(node, method_name)          methods.each do |method| -          next unless method.receiver.const_name == instance +          next unless method.receiver && method.receiver.const_name == instance            @offense_source_range = method.source_range            @offensive_node = method            yield method @@ -188,9 +192,15 @@ module RuboCop        end        # Returns an array of block nodes of any depth below node in AST +      # If a block is given then yields matching block node to the block!        def find_all_blocks(node, block_name)          return if node.nil? -        node.each_descendant(:block).select { |block_node| block_name == block_node.method_name } +        blocks = node.each_descendant(:block).select { |block_node| block_name == block_node.method_name } +        return blocks unless block_given? +        blocks.each do |block_node| +          offending_node(block_node) +          yield block_node +        end        end        # Returns a method definition node with method_name  | 
