Sha256: 869b89a8f80fc85e9715b2024919f4002307ea85430785138ee6fbf31102d83a

Contents?: true

Size: 1.58 KB

Versions: 6833

Compression:

Stored size: 1.58 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`.'.freeze

        def_node_matcher :add_offense_kwargs, <<-PATTERN
          (send nil? :add_offense _ $hash)
        PATTERN

        def_node_matcher :redundant_location_argument?, <<-PATTERN
          (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

        private

        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

        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

6,833 entries across 6,827 versions & 26 rubygems

Version Path
ory-client-0.0.1.alpha79 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha78 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha77 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha76 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha75 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha74 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha73 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha72 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha71 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha70 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha69 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha68 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha67 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha66 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-oathkeeper-client-0.38.19.beta1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-oathkeeper-client-0.38.18.beta1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-oathkeeper-client-0.38.17.beta1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
avalara_sdk-2.4.7 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha58 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
ory-client-0.0.1.alpha57 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb