Merge pull request #3518 from GauthamGoli/audit_bug_fix
lines_cop: Convert ARGV audit to negative look ahead
This commit is contained in:
commit
780e86904b
@ -127,6 +127,22 @@ module RuboCop
|
||||
end
|
||||
end
|
||||
|
||||
# Matches receiver part of method,
|
||||
# EX: to match `ARGV.<whatever>()`
|
||||
# call `find_instance_call(node, "ARGV")`
|
||||
# yields to a block with parent node of receiver
|
||||
def find_instance_call(node, name)
|
||||
node.each_descendant(:send) do |method_node|
|
||||
next if method_node.receiver.nil?
|
||||
next if method_node.receiver.const_name != name &&
|
||||
method_node.receiver.method_name != name
|
||||
@offense_source_range = method_node.receiver.source_range
|
||||
@offensive_node = method_node.receiver
|
||||
return true unless block_given?
|
||||
yield method_node
|
||||
end
|
||||
end
|
||||
|
||||
# Returns nil if does not depend on dependency_name
|
||||
# args: node - dependency_name - dependency's name
|
||||
def depends_on?(dependency_name, *types)
|
||||
|
||||
@ -162,10 +162,9 @@ module RuboCop
|
||||
end
|
||||
end
|
||||
|
||||
[:debug?, :verbose?, :value].each do |method_name|
|
||||
find_instance_method_call(body_node, "ARGV", method_name) do
|
||||
problem "Use build instead of ARGV to check options"
|
||||
end
|
||||
find_instance_call(body_node, "ARGV") do |method_node|
|
||||
next if [:debug?, :verbose?, :value].index(method_node.method_name)
|
||||
problem "Use build instead of ARGV to check options"
|
||||
end
|
||||
|
||||
find_instance_method_call(body_node, :man, :+) do |method|
|
||||
|
||||
@ -541,13 +541,12 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
||||
end
|
||||
|
||||
it "Using ARGV to check options" do
|
||||
expect_offense(<<~RUBY)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
def install
|
||||
verbose = ARGV.verbose?
|
||||
^^^^^^^^^^^^^ Use build instead of ARGV to check options
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
@ -739,6 +738,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
||||
test do
|
||||
head = ARGV.include? "--HEAD"
|
||||
^^^^^^ Use "if build.head?" instead
|
||||
^^^^ Use build instead of ARGV to check options
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user