lib/rubocop/cop/cop.rb in rubocop-0.26.1 vs lib/rubocop/cop/cop.rb in rubocop-0.27.0
- old
+ new
@@ -63,23 +63,24 @@
found_ns = @all.types.map(&:capitalize).select do |ns|
@cop_names.include?("#{ns}/#{basename}")
end
case found_ns.size
- 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}"
+ when 0 then name # No namespace found. Deal with it later in caller.
+ when 1 then cop_name_with_namespace(name, origin, basename, found_ns[0])
+ else fail AmbiguousCopName, "`#{basename}` used in #{origin}"
end
end
+ def self.cop_name_with_namespace(name, origin, basename, found_ns)
+ if name != basename && found_ns != File.dirname(name).to_sym
+ warn "#{origin}: #{name} has the wrong namespace - should be " \
+ "#{found_ns}"
+ end
+ "#{found_ns}/#{basename}"
+ end
+
def self.non_rails
@all.without_type(:rails)
end
def self.inherited(subclass)
@@ -206,12 +207,12 @@
return unless severity
if Severity::NAMES.include?(severity.to_sym)
severity.to_sym
else
- warn "Warning: Invalid severity '#{severity}'. " +
+ warn("Warning: Invalid severity '#{severity}'. " +
"Valid severities are #{Severity::NAMES.join(', ')}."
- .color(:red)
+ .color(:red))
end
end
end
end
end