aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGautham Goli2017-07-29 16:36:32 +0530
committerGautham Goli2017-07-29 16:36:32 +0530
commite1cb0b43d7e3095de97b63c4776f9709120b7fad (patch)
tree61881aa40822d6b69b2da43fd5bc8921438a553b
parenta49d99a2d6a22f9db1540cb546ac2d7be2fb5703 (diff)
downloadbrew-e1cb0b43d7e3095de97b63c4776f9709120b7fad.tar.bz2
audit: Port dependency rules from line_problems to rubocop and add tests
-rw-r--r--Library/Homebrew/dev-cmd/audit.rb10
-rw-r--r--Library/Homebrew/rubocops.rb1
-rw-r--r--Library/Homebrew/rubocops/extend/formula_cop.rb3
-rw-r--r--Library/Homebrew/rubocops/lines_cop.rb20
-rw-r--r--Library/Homebrew/test/rubocops/lines_cop_spec.rb53
5 files changed, 76 insertions, 11 deletions
diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb
index b15d719d2..bdb2b4a37 100644
--- a/Library/Homebrew/dev-cmd/audit.rb
+++ b/Library/Homebrew/dev-cmd/audit.rb
@@ -909,16 +909,6 @@ class FormulaAuditor
problem "\"#{Regexp.last_match(1)}\" should be \"\#{#{Regexp.last_match(2)}}\""
end
- if line =~ /depends_on :(automake|autoconf|libtool)/
- problem ":#{Regexp.last_match(1)} is deprecated. Usage should be \"#{Regexp.last_match(1)}\""
- end
-
- if line =~ /depends_on :apr/
- problem ":apr is deprecated. Usage should be \"apr-util\""
- end
-
- problem ":tex is deprecated" if line =~ /depends_on :tex/
-
if line =~ /depends_on\s+['"](.+)['"]\s+=>\s+:(lua|perl|python|ruby)(\d*)/
problem "#{Regexp.last_match(2)} modules should be vendored rather than use deprecated `depends_on \"#{Regexp.last_match(1)}\" => :#{Regexp.last_match(2)}#{Regexp.last_match(3)}`"
end
diff --git a/Library/Homebrew/rubocops.rb b/Library/Homebrew/rubocops.rb
index 7d104ad9e..4323e044c 100644
--- a/Library/Homebrew/rubocops.rb
+++ b/Library/Homebrew/rubocops.rb
@@ -10,3 +10,4 @@ require_relative "./rubocops/legacy_patches_cop"
require_relative "./rubocops/conflicts_cop"
require_relative "./rubocops/options_cop"
require_relative "./rubocops/urls_cop"
+require_relative "./rubocops/lines_cop"
diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb
index 7165ee354..e42d6ee19 100644
--- a/Library/Homebrew/rubocops/extend/formula_cop.rb
+++ b/Library/Homebrew/rubocops/extend/formula_cop.rb
@@ -124,7 +124,8 @@ module RuboCop
case type
when :required
- type_match = !node.method_args.nil? && node.method_args.first.str_type?
+ type_match = !node.method_args.nil? &&
+ (node.method_args.first.str_type? || node.method_args.first.sym_type?)
if type_match && !name_match
name_match = node_equals?(node.method_args.first, name)
end
diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb
new file mode 100644
index 000000000..22039869b
--- /dev/null
+++ b/Library/Homebrew/rubocops/lines_cop.rb
@@ -0,0 +1,20 @@
+require_relative "./extend/formula_cop"
+
+module RuboCop
+ module Cop
+ module FormulaAudit
+ # This cop checks for various miscellaneous Homebrew coding styles
+ class Lines < FormulaCop
+ def audit_formula(_node, _class_node, _parent_class_node, _body_node)
+ [:automake, :autoconf, :libtool].each do |dependency|
+ next unless depends_on?(dependency)
+ problem ":#{dependency} is deprecated. Usage should be \"#{dependency}\""
+ end
+
+ problem ':apr is deprecated. Usage should be "apr-util"' if depends_on?(:apr)
+ problem ":tex is deprecated" if depends_on?(:tex)
+ end
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
new file mode 100644
index 000000000..c865e1480
--- /dev/null
+++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
@@ -0,0 +1,53 @@
+require "rubocop"
+require "rubocop/rspec/support"
+require_relative "../../extend/string"
+require_relative "../../rubocops/lines_cop"
+
+describe RuboCop::Cop::FormulaAudit::Lines do
+ subject(:cop) { described_class.new }
+
+ context "When auditing lines" do
+ it "with correctable deprecated dependencies" do
+ formulae = [{
+ "dependency" => :automake,
+ "correct" => "automake",
+ }, {
+ "dependency" => :autoconf,
+ "correct" => "autoconf",
+ }, {
+ "dependency" => :libtool,
+ "correct" => "libtool",
+ }, {
+ "dependency" => :apr,
+ "correct" => "apr-util",
+ }, {
+ "dependency" => :tex,
+ }]
+
+ formulae.each do |formula|
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ depends_on :#{formula["dependency"]}
+ end
+ EOS
+ if formula.key?("correct")
+ offense = ":#{formula["dependency"]} is deprecated. Usage should be \"#{formula["correct"]}\""
+ else
+ offense = ":#{formula["dependency"]} is deprecated"
+ end
+ expected_offenses = [{ message: offense,
+ severity: :convention,
+ line: 3,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses.reverse).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ end
+ end
+end