diff options
| author | Gautham Goli | 2017-08-04 01:18:00 +0530 |
|---|---|---|
| committer | Gautham Goli | 2017-09-04 15:05:43 +0530 |
| commit | 267def28faab69388be3bc6347c0644f6ca812e8 (patch) | |
| tree | 2661e64f50ae36b17819ce7cced1ca9ba6c1bfb1 /Library/Homebrew/rubocops/extend | |
| parent | 751334a257d81851e68da7ab390982d4e9fdf909 (diff) | |
| download | brew-267def28faab69388be3bc6347c0644f6ca812e8.tar.bz2 | |
audit: Port rules from line_problems to rubocop part 3
Diffstat (limited to 'Library/Homebrew/rubocops/extend')
| -rw-r--r-- | Library/Homebrew/rubocops/extend/formula_cop.rb | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index 7844f7bf2..4aec1a4c9 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -4,12 +4,13 @@ require_relative "../../extend/string" module RuboCop module Cop class FormulaCop < Cop + attr_accessor :file_path @registry = Cop.registry # This method is called by RuboCop and is the main entry point def on_class(node) - file_path = processed_source.buffer.name - return unless file_path_allowed?(file_path) + @file_path = processed_source.buffer.name + return unless file_path_allowed? return unless formula_class?(node) return unless respond_to?(:audit_formula) class_node, parent_class_node, @body = *node @@ -100,8 +101,7 @@ module RuboCop def find_method_with_args(node, method_name, *args) methods = find_every_method_call_by_name(node, method_name) methods.each do |method| - next unless parameters_passed?(method, *args) - yield method + yield method if parameters_passed?(method, *args) end end @@ -112,7 +112,9 @@ module RuboCop def find_instance_method_call(node, instance, method_name) methods = find_every_method_call_by_name(node, method_name) methods.each do |method| - next unless method.receiver && method.receiver.const_name == instance + next if method.receiver.nil? + next if method.receiver.const_name != instance && + method.receiver.method_name != instance @offense_source_range = method.source_range @offensive_node = method yield method @@ -414,6 +416,12 @@ module RuboCop method_name(component_node) if component_node.def_type? end + # Returns the formula tap + def formula_tap + return unless match_obj = @file_path.match(%r{/(homebrew-\w+)/}) + match_obj[1] + end + def problem(msg) add_offense(@offensive_node, @offense_source_range, msg) end @@ -425,11 +433,11 @@ module RuboCop class_node && string_content(class_node) == "Formula" end - def file_path_allowed?(file_path) + def file_path_allowed? paths_to_exclude = [%r{/Library/Homebrew/compat/}, %r{/Library/Homebrew/test/}] - return true if file_path.nil? # file_path is nil when source is directly passed to the cop eg., in specs - file_path !~ Regexp.union(paths_to_exclude) + return true if @file_path.nil? # file_path is nil when source is directly passed to the cop eg., in specs + @file_path !~ Regexp.union(paths_to_exclude) end end end |
