aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/rubocops
diff options
context:
space:
mode:
authorGautham Goli2017-08-30 15:48:41 +0530
committerGautham Goli2017-09-04 15:05:43 +0530
commit337d5c64708f3ad1d7074e17b1cd5be24e0ee488 (patch)
treee398d4f2aba4e0e7ca2571eb73e50f79c9240163 /Library/Homebrew/rubocops
parentb582ed513b3b28197369cb3cf808e9c4025ee581 (diff)
downloadbrew-337d5c64708f3ad1d7074e17b1cd5be24e0ee488.tar.bz2
audit: Fetch formula name from file path rather than class name in cops
Diffstat (limited to 'Library/Homebrew/rubocops')
-rw-r--r--Library/Homebrew/rubocops/conflicts_cop.rb2
-rw-r--r--Library/Homebrew/rubocops/extend/formula_cop.rb9
-rw-r--r--Library/Homebrew/rubocops/lines_cop.rb11
3 files changed, 9 insertions, 13 deletions
diff --git a/Library/Homebrew/rubocops/conflicts_cop.rb b/Library/Homebrew/rubocops/conflicts_cop.rb
index c1b801559..6f05d0567 100644
--- a/Library/Homebrew/rubocops/conflicts_cop.rb
+++ b/Library/Homebrew/rubocops/conflicts_cop.rb
@@ -18,7 +18,7 @@ module RuboCop
def audit_formula(_node, _class_node, _parent_class_node, body)
return unless versioned_formula?
- problem MSG if !formula_file_name.start_with?(*WHITELIST) &&
+ problem MSG if !@formula_name.start_with?(*WHITELIST) &&
method_called_ever?(body, :conflicts_with)
end
end
diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb
index c8288ef9f..75d043f30 100644
--- a/Library/Homebrew/rubocops/extend/formula_cop.rb
+++ b/Library/Homebrew/rubocops/extend/formula_cop.rb
@@ -14,7 +14,7 @@ module RuboCop
return unless formula_class?(node)
return unless respond_to?(:audit_formula)
class_node, parent_class_node, @body = *node
- @formula_name = class_name(class_node)
+ @formula_name = Pathname.new(@file_path).basename(".rb").to_s
audit_formula(node, class_node, parent_class_node, @body)
end
@@ -404,12 +404,7 @@ module RuboCop
# Returns true if the formula is versioned
def versioned_formula?
- formula_file_name.include?("@") || @formula_name.match(/AT\d+/)
- end
-
- # Returns filename of the formula without the extension
- def formula_file_name
- File.basename(processed_source.buffer.name, ".rb")
+ @formula_name.include?("@")
end
# Returns printable component name
diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb
index ab10f6552..01b13585c 100644
--- a/Library/Homebrew/rubocops/lines_cop.rb
+++ b/Library/Homebrew/rubocops/lines_cop.rb
@@ -21,7 +21,7 @@ module RuboCop
begin_pos = start_column(parent_class_node)
end_pos = end_column(class_node)
return unless begin_pos-end_pos != 3
- problem "Use a space in class inheritance: class #{@formula_name} < #{class_name(parent_class_node)}"
+ problem "Use a space in class inheritance: class #{class_name(class_node)} < #{class_name(parent_class_node)}"
end
end
@@ -86,12 +86,13 @@ module RuboCop
end
find_method_with_args(body_node, :system, /^(otool|install_name_tool|lipo)$/) do
- next if @formula_name == "Cctools"
+ next if @formula_name == "cctools"
problem "Use ruby-macho instead of calling #{@offensive_node.source}"
end
find_every_method_call_by_name(body_node, :system).each do |method_node|
- next if @formula_name =~ /^Kibana(\@\d+(\.\d+)?)?$/
+ # Skip Kibana: npm cache edge (see formula for more details)
+ next if @formula_name =~ /^kibana(\@\d+(\.\d+)?)?$/
first_param, second_param = parameters(method_node)
next if !node_equals?(first_param, "npm") ||
!node_equals?(second_param, "install")
@@ -115,8 +116,8 @@ module RuboCop
end
find_instance_method_call(body_node, :build, :universal?) do
- next if @formula_name == "Wine"
- problem "macOS has been 64-bit only so build.universal? is deprecated."
+ next if @formula_name == "wine"
+ problem "macOS has been 64-bit only since 10.6 so build.universal? is deprecated."
end
find_instance_method_call(body_node, "ENV", :universal_binary) do