class RuboCop::Cop::Cop

See docs.rubocop.org/rubocop/v1_upgrade_notes.html<br>Legacy scaffold for Cops.
@deprecated Use Cop::Base instead

def self.all

Deprecated:
  • Use Registry.all
def self.all
  Registry.all
end

def self.joining_forces

def self.joining_forces
  return unless method_defined?(:join_force?)
  cop = new
  Force.all.select { |force_class| cop.join_force?(force_class) }
end

def self.qualified_cop_name(name, origin)

Deprecated:
  • Use Registry.qualified_cop_name
def self.qualified_cop_name(name, origin)
  Registry.qualified_cop_name(name, origin)
end

def self.registry

Deprecated:
  • Use Registry.global
def self.registry
  Registry.global
end

def self.support_autocorrect?

def self.support_autocorrect?
  method_defined?(:autocorrect)
end

def add_offense(node_or_range, location: :expression, message: nil, severity: nil, &block)

def add_offense(node_or_range, location: :expression, message: nil, severity: nil, &block)
  @v0_argument = node_or_range
  range = find_location(node_or_range, location)
  if block.nil? && !support_autocorrect?
    super(range, message: message, severity: severity)
  else
    super(range, message: message, severity: severity) do |corrector|
      emulate_v0_callsequence(corrector, &block)
    end
  end
end

def apply_correction(corrector)

def apply_correction(corrector)
  suppress_clobbering { super }
end

def begin_investigation(processed_source)

def begin_investigation(processed_source)
  super
  @offenses = current_offenses
  @last_corrector = @current_corrector
end

def callback_argument(_range)

Override Base
def callback_argument(_range)
  @v0_argument
end

def correction_lambda

def correction_lambda
  return unless support_autocorrect?
  dedup_on_node(@v0_argument) { autocorrect(@v0_argument) }
end

def corrections

Deprecated:
def corrections
  # warn 'Cop#corrections is deprecated' TODO
  return [] unless @last_corrector
  Legacy::CorrectionsProxy.new(@last_corrector)
end

def dedup_on_node(node)

def dedup_on_node(node)
  @corrected_nodes ||= {}.compare_by_identity
  yield unless @corrected_nodes.key?(node)
ensure
  @corrected_nodes[node] = true
end

def emulate_v0_callsequence(corrector)

Just for legacy
def emulate_v0_callsequence(corrector)
  lambda = correction_lambda
  yield corrector if block_given?
  unless corrector.empty?
    raise 'Your cop must inherit from Cop::Base and extend AutoCorrector'
  end
  return unless lambda
  suppress_clobbering { lambda.call(corrector) }
end

def find_location(node, loc)

def find_location(node, loc)
  # Location can be provided as a symbol, e.g.: `:keyword`
  loc.is_a?(Symbol) ? node.loc.public_send(loc) : loc
end

def highlights

def highlights
  offenses.sort.map { |o| o.location.source }
end

def messages

def messages
  offenses.sort.map(&:message)
end

def on_investigation_end

Called after all on_... have been called
def on_investigation_end
  investigate_post_walk(processed_source) if respond_to?(:investigate_post_walk)
  super
end

def on_new_investigation

Called before all on_... have been called
def on_new_investigation
  investigate(processed_source) if respond_to?(:investigate)
  super
end

def support_autocorrect?

Deprecated:
  • Use class method
def support_autocorrect?
  # warn 'deprecated, use cop.class.support_autocorrect?' TODO
  self.class.support_autocorrect?
end

def suppress_clobbering

def suppress_clobbering
  yield
rescue ::Parser::ClobberingError
  # ignore Clobbering errors
end