Sha256: b18963891fab6cbaa12e80f0846bf31754ade5f9558417d4bc3a5e6771875920

Contents?: true

Size: 1.1 KB

Versions: 84

Compression:

Stored size: 1.1 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.receiver
      #
      #   # good
      #   node.receiver
      #
      class RedundantMethodDispatchNode < Base
        include RangeHelp
        extend AutoCorrector

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

        # @!method dispatch_method(node)
        def_node_matcher :dispatch_method, <<~PATTERN
          (send $(send _ :send_node) _)
        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

84 entries across 75 versions & 12 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.52.1/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
rubocop-1.56.2 lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
synctera_ruby_sdk-1.1.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
synctera_ruby_sdk-1.1.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
synctera_ruby_sdk-1.1.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
sampero-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.1/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
rubocop-1.56.1 lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
tursodb-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
synctera_ruby_sdk-1.0.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
rubocop-1.56.0 lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
rubocop-1.55.1 lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
rubocop-1.55.0 lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
rubocop-1.54.2 lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb