diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index dac523424498f57a972c2ada41124dfbcd10c6ee..6a6f348211af3b02bb1ee422e87ad9ac737aee33 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -88,11 +88,11 @@ module RuboCop end end - # [:debug?, :verbose?, :value].each do |m| - # find_instance_method_call(body_node, :ARGV, m) do - # problem "Use build instead of ARGV to check options" - # end - # end + [:debug?, :verbose?, :value].each do |m| + find_instance_method_call(body_node, "ARGV", m) do + problem "Use build instead of ARGV to check options" + end + end # # find_instance_method_call(body_node, :man, :+) do |m| # next unless match = regex_match_group(parameters(m).first, %r{man[1-8]}) @@ -320,7 +320,6 @@ module RuboCop next unless match = regex_match_group(arg, %r{\-\-(.*)}) problem "Reference '#{match[1]}' without dashes" end - end def unless_modifier?(node) diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 288ca8f8f02d0b75d24447e8ddab34dacc8caf8f..b5ff3d1f49883261f0522e12720a0f325f7e2522 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -811,6 +811,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with using ARGV to check options" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def test + verbose = ARGV.verbose? + end + end + EOS + + expected_offenses = [{ message: "Use build instead of ARGV to check options", + 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])