Sha256: add3195e938b1f2f4b1c1f351dcd06e32f517ae4d66ffbf8ade1d6bb01569414

Contents?: true

Size: 1.25 KB

Versions: 46

Compression:

Stored size: 1.25 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 < Cop
        include RangeHelp

        MSG = 'Redundant location argument to `#add_offense`.'

        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) { |argument| add_offense(argument) }
        end

        def autocorrect(node)
          range = offending_range(node)

          ->(corrector) { corrector.remove(range) }
        end

        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

46 entries across 35 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.88.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.87.1 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.87.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.86.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.85.1 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.85.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.84.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.83.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.82.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.81.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.80.1 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.80.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb