Sha256: 16984bb919ccd08a3636834c77de8e703e556c4f9b498e5adf6f6af251344f1a

Contents?: true

Size: 894 Bytes

Versions: 23

Compression:

Stored size: 894 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Metrics
      module Utils
        # @api private
        #
        # Helps to calculate code length for the provided node.
        module RepeatedCsendDiscount
          def reset_repeated_csend
            @repeated_csend = {}
          end

          def discount_for_repeated_csend?(csend_node)
            receiver = csend_node.receiver

            return false unless receiver.lvar_type?

            var_name = receiver.children.first
            seen = @repeated_csend.fetch(var_name) do
              @repeated_csend[var_name] = csend_node
              return false
            end

            !seen.equal?(csend_node)
          end

          def reset_on_lvasgn(node)
            var_name = node.children.first
            @repeated_csend.delete(var_name)
          end
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 3 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
rubocop-1.4.2 lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
rubocop-1.4.1 lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
rubocop-1.4.0 lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
rubocop-1.3.1 lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
rubocop-1.3.0 lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
rubocop-1.2.0 lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
rubocop-1.1.0 lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
rubocop-1.0.0 lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
rubocop-0.93.1 lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
rubocop-0.93.0 lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
rubocop-0.92.0 lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
rubocop-0.91.1 lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
rubocop-0.91.0 lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.90.0/lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb