Sha256: e81d9b0b9df8eaebf569ca09e10eed9303e8ade0dd42a6eb58f7d06f7b89a0b0

Contents?: true

Size: 1.28 KB

Versions: 230

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    class VariableForce
      # This class represents each reference of a variable.
      class Reference
        include Branchable

        VARIABLE_REFERENCE_TYPES = (
          [VARIABLE_REFERENCE_TYPE] + OPERATOR_ASSIGNMENT_TYPES + [ZERO_ARITY_SUPER_TYPE, SEND_TYPE]
        ).freeze

        attr_reader :node, :scope

        def initialize(node, scope)
          unless VARIABLE_REFERENCE_TYPES.include?(node.type)
            raise ArgumentError,
                  "Node type must be any of #{VARIABLE_REFERENCE_TYPES}, " \
                  "passed #{node.type}"
          end

          @node = node
          @scope = scope
        end

        # There's an implicit variable reference by the zero-arity `super`:
        #
        #     def some_method(foo)
        #       super
        #     end
        #
        # Another case is `binding`:
        #
        #     def some_method(foo)
        #       do_something(binding)
        #     end
        #
        # In these cases, the variable `foo` is not explicitly referenced,
        # but it can be considered used implicitly by the `super` or `binding`.
        def explicit?
          ![ZERO_ARITY_SUPER_TYPE, SEND_TYPE].include?(@node.type)
        end
      end
    end
  end
end

Version data entries

230 entries across 221 versions & 22 rubygems

Version Path
harbr-0.1.89 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.88 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.87 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.86 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.85 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.84 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.83 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.82 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.81 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.80 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.79 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.78 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.77 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.76 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.75 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.74 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.73 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.72 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.71 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb
harbr-0.1.70 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/variable_force/reference.rb