Method: RuboCop::Cop::Base#add_offense

Defined in:
lib/rubocop/cop/base.rb

#add_offense(node_or_range, message: nil, severity: nil, &block) ⇒ Object

Adds an offense on the specified range (or node with an expression) Unless that offense is disabled for this range, a corrector will be yielded to provide the cop the opportunity to autocorrect the offense. If message is not specified, the method ‘message` will be called.

[View source]

201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/rubocop/cop/base.rb', line 201

def add_offense(node_or_range, message: nil, severity: nil, &block)
  range = range_from_node_or_range(node_or_range)
  return unless current_offense_locations.add?(range)

  range_to_pass = callback_argument(range)

  severity = find_severity(range_to_pass, severity)
  message = find_message(range_to_pass, message)

  status, corrector = enabled_line?(range.line) ? correct(range, &block) : :disabled

  # Since this range may be generated from Ruby code embedded in some
  # template file, we convert it to location info in the original file.
  range = range_for_original(range)

  current_offenses << Offense.new(severity, range, message, name, status, corrector)
end