Merge pull request #3366 from GauthamGoli/lines-cop-false-positives-fix
lines_cop: Fix detection of negated expression
This commit is contained in:
commit
40b212322c
@ -316,8 +316,10 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Check if negation is present in the given node
|
# Check if negation is present in the given node
|
||||||
def negated?(node)
|
def expression_negated?(node)
|
||||||
method_called?(node, :!)
|
return false if node.parent.nil?
|
||||||
|
return false unless node.parent.method_name.equal?(:!)
|
||||||
|
offending_node(node.parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return all the caveats' string nodes in an array
|
# Return all the caveats' string nodes in an array
|
||||||
|
|||||||
@ -94,12 +94,12 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
find_instance_method_call(body_node, :build, :with?) do |method|
|
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?'"
|
problem "Don't negate 'build.with?': use 'build.without?'"
|
||||||
end
|
end
|
||||||
|
|
||||||
find_instance_method_call(body_node, :build, :without?) do |method|
|
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?'"
|
problem "Don't negate 'build.without?': use 'build.with?'"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user