Merge pull request #3366 from GauthamGoli/lines-cop-false-positives-fix

lines_cop: Fix detection of negated expression
This commit is contained in:
Mike McQuaid 2017-10-26 15:28:40 +01:00 committed by GitHub
commit 40b212322c
2 changed files with 6 additions and 4 deletions

View File

@ -316,8 +316,10 @@ module RuboCop
end
# Check if negation is present in the given node
def negated?(node)
method_called?(node, :!)
def expression_negated?(node)
return false if node.parent.nil?
return false unless node.parent.method_name.equal?(:!)
offending_node(node.parent)
end
# Return all the caveats' string nodes in an array

View File

@ -94,12 +94,12 @@ module RuboCop
end
find_instance_method_call(body_node, :build, :with?) do |method|
next unless negated?(method.parent)
next unless expression_negated?(method)
problem "Don't negate 'build.with?': use 'build.without?'"
end
find_instance_method_call(body_node, :build, :without?) do |method|
next unless negated?(method.parent)
next unless expression_negated?(method)
problem "Don't negate 'build.without?': use 'build.with?'"
end