Sha256: 08199d0876e1da7ac9acaa7f5d225f2f9913c0235952c3b19952f5cefe69c81b

Contents?: true

Size: 1.34 KB

Versions: 117

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module InternalAffairs
      # Checks for redundant `send_node` method dispatch node.
      #
      # @example
      #
      #   # bad
      #   node.send_node.method_name
      #
      #   # good
      #   node.method_name
      #
      #   # bad
      #   node.send_node.method?(:method_name)
      #
      #   # good
      #   node.method?(:method_name)
      #
      #   # bad
      #   node.send_node.receiver
      #
      #   # good
      #   node.receiver
      #
      class RedundantMethodDispatchNode < Base
        include RangeHelp
        extend AutoCorrector

        MSG = 'Remove the redundant `send_node`.'
        RESTRICT_ON_SEND = %i[method_name method? receiver].freeze

        # @!method dispatch_method(node)
        def_node_matcher :dispatch_method, <<~PATTERN
          {
            (send $(send _ :send_node) {:method_name :receiver})
            (send $(send _ :send_node) :method? _)
          }
        PATTERN

        def on_send(node)
          return unless (dispatch_node = dispatch_method(node))
          return unless (dot = dispatch_node.loc.dot)

          range = range_between(dot.begin_pos, dispatch_node.loc.selector.end_pos)

          add_offense(range) do |corrector|
            corrector.remove(range)
          end
        end
      end
    end
  end
end

Version data entries

117 entries across 117 versions & 8 rubygems

Version Path
harbr-0.1.61 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.60 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.59 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.58 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.57 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.56 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.55 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.54 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.53 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.52 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.50 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.49 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.48 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.47 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.46 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.45 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.44 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.43 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.42 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
harbr-0.1.41 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb