aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorGautham Goli2017-08-14 00:02:44 +0530
committerGautham Goli2017-08-14 00:02:44 +0530
commita73c29fef21ccb7f45243500f04f1ed9965fdf38 (patch)
treebf9e910a427cb874cb8a242ed98798030a106780 /Library
parent77105b809a83583e3da5726105dc9cd913112913 (diff)
downloadbrew-a73c29fef21ccb7f45243500f04f1ed9965fdf38.tar.bz2
add tests for non glob dirs audit
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/rubocops/lines_cop.rb13
-rw-r--r--Library/Homebrew/test/rubocops/lines_cop_spec.rb23
2 files changed, 31 insertions, 5 deletions
diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb
index 604de5af9..7a0e08ba2 100644
--- a/Library/Homebrew/rubocops/lines_cop.rb
+++ b/Library/Homebrew/rubocops/lines_cop.rb
@@ -255,11 +255,14 @@ module RuboCop
problem "\"#{m.source}\" is deprecated, use a comparison to MacOS.version instead"
end
end
- #
- # dirPattern(body_node) do |m|
- # next unless m =~ /\[("[^\*{},]+")\]/
- # problem "Dir(#{Regexp.last_match(1)}) is unnecessary; just use #{Regexp.last_match(1)}"
- # end
+
+ find_instance_method_call(body_node, "Dir", :[]) do |m|
+ path = parameters(m).first
+ next if !path.str_type?
+ next unless match = regex_match_group(path, /^[^\*{},]+$/)
+ problem "Dir([\"#{string_content(path)}\"]) is unnecessary; just use \"#{match[0]}\""
+ end
+
#
# fileUtils_methods= FileUtils.singleton_methods(false).map { |m| Regexp.escape(m) }.join "|"
# find_method_with_args(body_node, :system, /fileUtils_methods/) do |m|
diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
index 69caee80c..203f8a7d9 100644
--- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb
+++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
@@ -552,6 +552,29 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
expect_offense(expected, actual)
end
end
+
+ it "with non glob DIR" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ rm_rf Dir["src/{llvm,test,librustdoc,etc/snapshot.pyc}"]
+ rm_rf Dir["src/snapshot.pyc"]
+ end
+ EOS
+
+ expected_offenses = [{ message: "Dir([\"src/snapshot.pyc\"]) is unnecessary; just use \"src/snapshot.pyc\"",
+ severity: :convention,
+ line: 5,
+ column: 13,
+ 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])