From 09326909afa83893fa92edfd47820e736f5bf334 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Wed, 25 Oct 2017 16:05:29 +0530 Subject: [PATCH] lines_cop: Fix detection of negated expression --- Library/Homebrew/rubocops/extend/formula_cop.rb | 6 ++++-- Library/Homebrew/rubocops/lines_cop.rb | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index 2e9a7657ed..1e7160bbd4 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -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 diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index c5f2e75850..e8aa6a53f6 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -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