lib/rubocop/cop/cop.rb in rubocop-0.28.0 vs lib/rubocop/cop/cop.rb in rubocop-0.29.0
- old
+ new
@@ -13,16 +13,16 @@
@types
end
# @return [Array<Cop>] Cops for that specific type.
def with_type(type)
- select { |c| c.cop_type == type }
+ CopStore.new(select { |c| c.cop_type == type })
end
# @return [Array<Cop>] Cops not for a specific type.
def without_type(type)
- reject { |c| c.cop_type == type }
+ CopStore.new(reject { |c| c.cop_type == type })
end
end
# A scaffold for concrete cops.
#
@@ -52,15 +52,15 @@
attr_accessor :processed_source # TODO: Bad design.
@all = CopStore.new
def self.all
- @all.clone
+ @all.without_type(:test)
end
def self.qualified_cop_name(name, origin)
- @cop_names ||= Set.new(@all.map(&:cop_name))
+ @cop_names ||= Set.new(all.map(&:cop_name))
basename = File.basename(name)
found_ns = @all.types.map(&:capitalize).select do |ns|
@cop_names.include?("#{ns}/#{basename}")
end
@@ -78,11 +78,11 @@
end
"#{found_ns}/#{basename}"
end
def self.non_rails
- @all.without_type(:rails)
+ all.without_type(:rails)
end
def self.inherited(subclass)
@all << subclass
end
@@ -126,11 +126,12 @@
def debug?
@options[:debug]
end
def display_cop_names?
- debug? || @options[:display_cop_names]
+ debug? || @options[:display_cop_names] ||
+ config['AllCops'] && config['AllCops']['DisplayCopNames']
end
def message(_node = nil)
self.class::MSG
end
@@ -185,11 +186,16 @@
private
def file_name_matches_any?(file, parameter, default_result)
patterns = cop_config && cop_config[parameter]
return default_result unless patterns
- path = config.path_relative_to_config(file)
+ path = nil
patterns.any? do |pattern|
+ # Try to match the absolute path, as Exclude properties are absolute.
+ next true if match_path?(pattern, file, config.loaded_path)
+
+ # Try with relative path.
+ path ||= config.path_relative_to_config(file)
match_path?(pattern, path, config.loaded_path)
end
end
def enabled_line?(line_number)