Sha256: 1a926ba2a01944748b719df69c4fbf33e582d382c1e09b21b047958d065fad29

Contents?: true

Size: 926 Bytes

Versions: 4

Compression:

Stored size: 926 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module InternalAffairs
      # Checks for redundant `source_range`.
      #
      # @example
      #
      #   # bad
      #   node.source_range.source
      #
      #   # good
      #   node.source
      #
      class RedundantSourceRange < Base
        extend AutoCorrector

        MSG = 'Remove the redundant `source_range`.'
        RESTRICT_ON_SEND = %i[source].freeze

        # @!method redundant_source_range(node)
        def_node_matcher :redundant_source_range, <<~PATTERN
          (send $(send _ :source_range) :source)
        PATTERN

        def on_send(node)
          return unless (source_range = redundant_source_range(node))

          selector = source_range.loc.selector

          add_offense(selector) do |corrector|
            corrector.remove(source_range.loc.dot.join(selector))
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
call_your_name-0.1.0 vendor/bundle/ruby/3.1.0/gems/rubocop-1.48.1/lib/rubocop/cop/internal_affairs/redundant_source_range.rb
rubocop-1.48.1 lib/rubocop/cop/internal_affairs/redundant_source_range.rb
rubocop-1.48.0 lib/rubocop/cop/internal_affairs/redundant_source_range.rb
rubocop-1.47.0 lib/rubocop/cop/internal_affairs/redundant_source_range.rb