aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/rubocops
diff options
context:
space:
mode:
authorGautham Goli2017-08-06 14:48:39 +0530
committerGautham Goli2017-08-07 16:02:50 +0530
commita3219ca09cded33f80c2039c29f191b7369e2450 (patch)
tree4c68d1413f685bc0b76818b79a73233189688a0e /Library/Homebrew/rubocops
parent8e89b9d9d06e52d183b9382fdb316139f1922f27 (diff)
downloadbrew-a3219ca09cded33f80c2039c29f191b7369e2450.tar.bz2
Add node pattern methods to handle dependency audits in a better way
Diffstat (limited to 'Library/Homebrew/rubocops')
-rw-r--r--Library/Homebrew/rubocops/extend/formula_cop.rb28
1 files changed, 21 insertions, 7 deletions
diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb
index 4be0c0fe3..862664010 100644
--- a/Library/Homebrew/rubocops/extend/formula_cop.rb
+++ b/Library/Homebrew/rubocops/extend/formula_cop.rb
@@ -1,4 +1,5 @@
require "parser/current"
+require_relative "../../extend/string"
module RuboCop
module Cop
@@ -138,17 +139,14 @@ module RuboCop
case type
when :required
- type_match = !node.method_args.nil? &&
- (node.method_args.first.str_type? || node.method_args.first.sym_type?)
+ type_match = required_dependency?(node)
if type_match && !name_match
- name_match = node_equals?(node.method_args.first, name)
+ name_match = required_dependency_name?(node, name)
end
when :build, :optional, :recommended, :run
- type_match = !node.method_args.nil? &&
- node.method_args.first.hash_type? &&
- node.method_args.first.values.first.children.first == type
+ type_match = dependency_type_hash_match?(node, type)
if type_match && !name_match
- name_match = node_equals?(node.method_args.first.keys.first.children.first, name)
+ name_match = dependency_name_hash_match?(node, name)
end
else
type_match = false
@@ -161,6 +159,22 @@ module RuboCop
type_match && name_match
end
+ def_node_search :required_dependency?, <<-EOS.undent
+ (send nil :depends_on ({str sym} _))
+ EOS
+
+ def_node_search :required_dependency_name?, <<-EOS.undent
+ (send nil :depends_on ({str sym} %1))
+ EOS
+
+ def_node_search :dependency_type_hash_match?, <<-EOS.undent
+ (hash (pair ({str sym} _) ({str sym} %1)))
+ EOS
+
+ def_node_search :dependency_name_hash_match?, <<-EOS.undent
+ (hash (pair ({str sym} %1) ({str sym} _)))
+ EOS
+
# To compare node with appropriate Ruby variable
def node_equals?(node, var)
node == Parser::CurrentRuby.parse(var.inspect)