add tests for dependencies
This commit is contained in:
parent
d2a7314f53
commit
cfc423e183
@ -148,13 +148,15 @@ module RuboCop
|
|||||||
problem "Use ENV instead of invoking '#{match[1]}' to modify the environment"
|
problem "Use ENV instead of invoking '#{match[1]}' to modify the environment"
|
||||||
end
|
end
|
||||||
|
|
||||||
# find_every_method_call_by_name(body_node, :depends_on).each do |m|
|
find_every_method_call_by_name(body_node, :depends_on).each do |m|
|
||||||
# next unless modifier?(m)
|
next if modifier?(m.parent)
|
||||||
# dep, option = hash_dep(m)
|
param = parameters(m).first
|
||||||
# next if dep.nil? || option.nil?
|
dep, option = hash_dep(param)
|
||||||
# problem "Dependency #{string_content(dep)} should not use option #{string_content(option)}"
|
next if dep.nil? || option.nil?
|
||||||
# end
|
offending_node(param)
|
||||||
#
|
problem "Dependency #{string_content(dep)} should not use option #{string_content(option)}"
|
||||||
|
end
|
||||||
|
|
||||||
# find_instance_method_call(body_node, :version, :==) do |m|
|
# find_instance_method_call(body_node, :version, :==) do |m|
|
||||||
# next unless parameters_passed?(m, "HEAD")
|
# next unless parameters_passed?(m, "HEAD")
|
||||||
# problem "Use 'build.head?' instead of inspecting 'version'"
|
# problem "Use 'build.head?' instead of inspecting 'version'"
|
||||||
@ -328,6 +330,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def modifier?(node)
|
def modifier?(node)
|
||||||
|
return false unless node.if_type?
|
||||||
node.modifier_form?
|
node.modifier_form?
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -340,9 +343,9 @@ module RuboCop
|
|||||||
EOS
|
EOS
|
||||||
|
|
||||||
# Match depends_on with hash as argument
|
# Match depends_on with hash as argument
|
||||||
def_node_search :hash_dep, <<-EOS.undent
|
def_node_matcher :hash_dep, <<-EOS.undent
|
||||||
{$(hash (pair $(str _) $(str _)))
|
{(hash (pair $(str _) $(str _)))
|
||||||
$(hash (pair $(str _) (array $(str _) ...)))}
|
(hash (pair $(str _) (array $(str _) ...)))}
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
def_node_matcher :destructure_hash, <<-EOS.undent
|
def_node_matcher :destructure_hash, <<-EOS.undent
|
||||||
|
|||||||
@ -1095,6 +1095,28 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "with dependencies with invalid options" do
|
||||||
|
source = <<-EOS.undent
|
||||||
|
class Foo < Formula
|
||||||
|
desc "foo"
|
||||||
|
url 'http://example.com/foo-1.0.tgz'
|
||||||
|
depends_on "foo" => "with-bar"
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
expected_offenses = [{ message: "Dependency foo should not use option with-bar",
|
||||||
|
severity: :convention,
|
||||||
|
line: 4,
|
||||||
|
column: 13,
|
||||||
|
source: source }]
|
||||||
|
|
||||||
|
inspect_source(cop, source)
|
||||||
|
|
||||||
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||||
|
expect_offense(expected, actual)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
def expect_offense(expected, actual)
|
def expect_offense(expected, actual)
|
||||||
expect(actual.message).to eq(expected[:message])
|
expect(actual.message).to eq(expected[:message])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user