lib/rubocop/cop/cop.rb in rubocop-0.43.0 vs lib/rubocop/cop/cop.rb in rubocop-0.44.0

- old
+ new

@@ -1,7 +1,7 @@ -# encoding: utf-8 # frozen_string_literal: true +require 'uri' module RuboCop module Cop class AmbiguousCopName < RuboCop::Error; end @@ -21,16 +21,15 @@ def without_type(type) CopStore.new(reject { |c| c.cop_type == type }) end def qualified_cop_name(name, origin) - @cop_names ||= Set.new(map(&:cop_name)) - return name if @cop_names.include?(name) + return name if cop_names.include?(name) basename = File.basename(name) found_ns = types.map(&:capitalize).select do |ns| - @cop_names.include?("#{ns}/#{basename}") + 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 cop_name_with_namespace(name, origin, basename, found_ns[0]) @@ -46,10 +45,16 @@ warn "#{origin}: #{name} has the wrong namespace - should be " \ "#{found_ns}" end "#{found_ns}/#{basename}" end + + private + + def cop_names + @cop_names ||= Set.new(map(&:cop_name)) + end end # A scaffold for concrete cops. # # The Cop class is meant to be extended. @@ -226,10 +231,15 @@ !relevant_file?(file) end def style_guide_url url = cop_config['StyleGuide'] - url.nil? || url.empty? ? nil : url + return nil if url.nil? || url.empty? + + base_url = config.for_all_cops['StyleGuideBaseURL'] + return url if base_url.nil? || base_url.empty? + + URI.join(base_url, url).to_s end def reference_url url = cop_config['Reference'] url.nil? || url.empty? ? nil : url