Add negated? method to formula cop and add tests for negated build.without?
This commit is contained in:
parent
e14fedd1b3
commit
3efba57cd9
@ -297,6 +297,11 @@ module RuboCop
|
||||
true
|
||||
end
|
||||
|
||||
# Check if negation is present in the given node
|
||||
def negated?(node)
|
||||
method_called?(node, :!)
|
||||
end
|
||||
|
||||
# Return all the caveats' string nodes in an array
|
||||
def caveats_strings
|
||||
find_strings(find_method_def(@body, :caveats))
|
||||
|
||||
@ -288,15 +288,15 @@ module RuboCop
|
||||
end
|
||||
|
||||
find_instance_method_call(body_node, :build, :with?) do |m|
|
||||
next unless method_called?(m.parent, :!)
|
||||
next unless negated?(m.parent)
|
||||
problem "Don't negate 'build.with?': use 'build.without?'"
|
||||
end
|
||||
|
||||
# find_instance_method_call(body_node, :build, :without?) do |m|
|
||||
# next unless negation?(m)
|
||||
# problem "Don't negate 'build.without?': use 'build.with?'"
|
||||
# end
|
||||
#
|
||||
find_instance_method_call(body_node, :build, :without?) do |m|
|
||||
next unless negated?(m.parent)
|
||||
problem "Don't negate 'build.without?': use 'build.with?'"
|
||||
end
|
||||
|
||||
# find_instance_method_call(body_node, :build, :without?) do |m|
|
||||
# arg = parameters(m).first
|
||||
# next unless match = regex_match_group(arg, %r{-?-?without-(.*)})
|
||||
|
||||
@ -691,6 +691,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
end
|
||||
|
||||
it "with negated build.with?" do
|
||||
source = <<-EOS.undent
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
def post_install
|
||||
return if !build.without? "bar"
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Don't negate 'build.without?': use 'build.with?'",
|
||||
severity: :convention,
|
||||
line: 5,
|
||||
column: 14,
|
||||
source: source }]
|
||||
|
||||
inspect_source(cop, source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
end
|
||||
end
|
||||
def expect_offense(expected, actual)
|
||||
expect(actual.message).to eq(expected[:message])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user