Sha256: 405c147334e06c0c0c25770dfd082936284c21bb8c5593dd26adae0399bccf19

Contents?: true

Size: 1.35 KB

Versions: 30

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module InternalAffairs
      # 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)
      #
      class RedundantLocationArgument < Base
        include RangeHelp
        extend AutoCorrector

        MSG = 'Redundant location argument to `#add_offense`.'
        RESTRICT_ON_SEND = %i[add_offense].freeze

        def_node_matcher :redundant_location_argument, <<~PATTERN
          (send nil? :add_offense _
            (hash <$(pair (sym :location) (sym :expression)) ...>)
          )
        PATTERN

        def on_send(node)
          redundant_location_argument(node) do |argument|
            add_offense(argument) do |corrector|
              range = offending_range(argument)

              corrector.remove(range)
            end
          end
        end

        private

        def offending_range(node)
          with_space = range_with_surrounding_space(range: node.loc.expression)

          range_with_surrounding_comma(with_space, :left)
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.10.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.9.1 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.9.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.8.1 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.8.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.7.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.6.1 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.6.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.5.2 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.5.1 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.5.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.4.2 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.4.1 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-1.4.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb