lines_cop: Add deprected options audit for depends_on
This commit is contained in:
parent
e7db10c928
commit
efec2fa0c5
@ -58,7 +58,7 @@ module RuboCop
|
||||
# Returns all string nodes among the descendants of given node
|
||||
def find_strings(node)
|
||||
return [] if node.nil?
|
||||
return node if node.str_type?
|
||||
return [node] if node.str_type?
|
||||
node.each_descendant(:str)
|
||||
end
|
||||
|
||||
|
||||
@ -228,12 +228,15 @@ module RuboCop
|
||||
end
|
||||
|
||||
find_every_method_call_by_name(body_node, :depends_on).each do |method|
|
||||
next if modifier?(method.parent)
|
||||
param = parameters(method).first
|
||||
dep, option = hash_dep(param)
|
||||
next if dep.nil? || option.nil?
|
||||
offending_node(param)
|
||||
problem "Dependency #{string_content(dep)} should not use option #{string_content(option)}"
|
||||
dep, option_child_nodes = hash_dep(param)
|
||||
next if dep.nil? || option_child_nodes.empty?
|
||||
option_child_nodes.each do |option|
|
||||
find_strings(option).each do |dependency|
|
||||
next unless match = regex_match_group(dependency, /(with(out)?-\w+|c\+\+11)/)
|
||||
problem "Dependency #{string_content(dep)} should not use option #{match[0]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
find_instance_method_call(body_node, :version, :==) do |method|
|
||||
@ -363,10 +366,8 @@ module RuboCop
|
||||
(send nil? :depends_on $({str sym} _)))}
|
||||
EOS
|
||||
|
||||
# Match depends_on with hash as argument
|
||||
def_node_matcher :hash_dep, <<~EOS
|
||||
{(hash (pair $(str _) $(str _)))
|
||||
(hash (pair $(str _) (array $(str _) ...)))}
|
||||
(hash (pair $(str _) $...))
|
||||
EOS
|
||||
|
||||
def_node_matcher :destructure_hash, <<~EOS
|
||||
|
||||
@ -693,13 +693,27 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "dependencies with invalid options" do
|
||||
it "dependencies with invalid options which lead to force rebuild" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
depends_on "foo" => "with-bar"
|
||||
^^^^^^^^^^^^^^^^^^^ Dependency foo should not use option with-bar
|
||||
^^^^^^^^ Dependency foo should not use option with-bar
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "dependencies with invalid options in array value which lead to force rebuild" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
depends_on "httpd" => [:build, :test]
|
||||
depends_on "foo" => [:optional, "with-bar"]
|
||||
^^^^^^^^ Dependency foo should not use option with-bar
|
||||
depends_on "icu4c" => [:optional, "c++11"]
|
||||
^^^^^ Dependency icu4c should not use option c++11
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user