Sha256: 21d8cfedca22dcd4535f5338f831286e0991becbfd20af9d76ba5f6f3f5e2e51

Contents?: true

Size: 1.25 KB

Versions: 14

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

14 entries across 14 versions & 2 rubygems

Version Path
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.72.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.71.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.70.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
rubocop-0.69.0 lib/rubocop/cop/internal_affairs/redundant_location_argument.rb