lib/rubocop/cop/cop.rb in rubocop-0.24.1 vs lib/rubocop/cop/cop.rb in rubocop-0.25.0
- old
+ new
@@ -56,19 +56,27 @@
def self.all
@all.clone
end
def self.qualified_cop_name(name, origin)
- return name if name.include?('/')
+ @cop_names ||= Set.new(@all.map(&:cop_name))
+ basename = File.basename(name)
found_ns = @all.types.map(&:capitalize).select do |ns|
- @all.map(&:cop_name).include?("#{ns}/#{name}")
+ @cop_names.include?("#{ns}/#{basename}")
end
case found_ns.size
- when 0 then name # No namespace found. Deal with it later in caller.
- when 1 then "#{found_ns.first}/#{name}"
- else fail AmbiguousCopName, "`#{name}` used in #{origin}"
+ when 0
+ name # No namespace found. Deal with it later in caller.
+ when 1
+ if name != basename && found_ns.first != File.dirname(name).to_sym
+ warn "#{origin}: #{name} has the wrong namespace - " \
+ "should be #{found_ns.first}"
+ end
+ "#{found_ns.first}/#{basename}"
+ else
+ fail AmbiguousCopName, "`#{basename}` used in #{origin}"
end
end
def self.non_rails
@all.without_type(:rails)
@@ -166,20 +174,13 @@
self.class.cop_name
end
alias_method :name, :cop_name
- def include_file?(file)
- file_name_matches_any?(file, 'Include', true)
- end
-
- def exclude_file?(file)
- file_name_matches_any?(file, 'Exclude', false)
- end
-
def relevant_file?(file)
- include_file?(file) && !exclude_file?(file)
+ file_name_matches_any?(file, 'Include', true) &&
+ !file_name_matches_any?(file, 'Exclude', false)
end
private
def file_name_matches_any?(file, parameter, default_result)
@@ -191,11 +192,10 @@
end
end
def enabled_line?(line_number)
return true unless @processed_source
- @processed_source.comment_config
- .cop_enabled_at_line?(self, line_number)
+ @processed_source.comment_config.cop_enabled_at_line?(self, line_number)
end
def default_severity
self.class.lint? ? :warning : :convention
end