class RuboCop::Cop::InternalAffairs::RedundantLocationArgument

Checks for redundant `location` argument to `#add_offense`. `location` argument has a default value of `:expression` and this method will automatically use it.

@example

# bad
add_offense(node, location: :expression)

# good
add_offense(node)
add_offense(node, location: :selector)

Constants

MSG

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/internal_affairs/redundant_location_argument.rb, line 33
def autocorrect(node)
  range = offending_range(node)

  ->(corrector) { corrector.remove(range) }
end
on_send(node) click to toggle source
# File lib/rubocop/cop/internal_affairs/redundant_location_argument.rb, line 29
def on_send(node)
  redundant_location_argument(node) { |argument| add_offense(argument) }
end

Private Instance Methods

offending_range(node) click to toggle source
# File lib/rubocop/cop/internal_affairs/redundant_location_argument.rb, line 50
def offending_range(node)
  with_space = range_with_surrounding_space(node.loc.expression)

  range_with_surrounding_comma(with_space, :left)
end
redundant_location_argument(node) { |result| ... } click to toggle source
# File lib/rubocop/cop/internal_affairs/redundant_location_argument.rb, line 41
def redundant_location_argument(node)
  add_offense_kwargs(node) do |kwargs|
    result =
      kwargs.pairs.find { |arg| redundant_location_argument?(arg) }

    yield result if result
  end
end