aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorGautham Goli2017-08-14 02:14:20 +0530
committerGautham Goli2017-08-14 02:14:20 +0530
commite14fedd1b35480ea3707689db044140d18662b9c (patch)
tree7f50c9888792b9d2cbd00e137d489004e47e08d1 /Library
parentec2b0df10e62152529386cf2a696f9aaece405ea (diff)
downloadbrew-e14fedd1b35480ea3707689db044140d18662b9c.tar.bz2
Add test for negated build.with?
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/rubocops/extend/formula_cop.rb8
-rw-r--r--Library/Homebrew/rubocops/lines_cop.rb11
-rw-r--r--Library/Homebrew/test/rubocops/lines_cop_spec.rb24
3 files changed, 36 insertions, 7 deletions
diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb
index cb404046c..94952d1f5 100644
--- a/Library/Homebrew/rubocops/extend/formula_cop.rb
+++ b/Library/Homebrew/rubocops/extend/formula_cop.rb
@@ -252,11 +252,15 @@ module RuboCop
end
# Check if method_name is called among the direct children nodes in the given node
+ # Check if the node itself is the method
def method_called?(node, method_name)
+ if node.send_type? && node.method_name == method_name
+ offending_node(node)
+ return true
+ end
node.each_child_node(:send) do |call_node|
next unless call_node.method_name == method_name
- @offensive_node = call_node
- @offense_source_range = call_node.source_range
+ offending_node(call_node)
return true
end
false
diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb
index 2b146b79e..4c82b42cf 100644
--- a/Library/Homebrew/rubocops/lines_cop.rb
+++ b/Library/Homebrew/rubocops/lines_cop.rb
@@ -287,11 +287,11 @@ module RuboCop
problem "Use if #{correct} instead of unless #{m.source}"
end
- # find_instance_method_call(body_node, :build, :with?) do |m|
- # next unless negation?(m)
- # problem "Don't negate 'build.with?': use 'build.without?'"
- # end
- #
+ find_instance_method_call(body_node, :build, :with?) do |m|
+ next unless method_called?(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?'"
@@ -324,6 +324,7 @@ module RuboCop
end
def unless_modifier?(node)
+ return false unless node.if_type?
node.modifier_form? && node.unless?
end
diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
index dda1b96e6..8e3f42adf 100644
--- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb
+++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
@@ -667,6 +667,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.with? "bar"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Don't negate 'build.with?': use 'build.without?'",
+ 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])