Sha256: 6b5b41e0645f8bc1fc3153502b581b45dd52bcef4677cfd67501a3748ce5b350

Contents?: true

Size: 1.28 KB

Versions: 11

Compression:

Stored size: 1.28 KB

Contents

# encoding: utf-8

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

        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)
            fail 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

11 entries across 11 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.35.0 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.34.2 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.34.1 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.34.0 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.33.0 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.32.1 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.32.0 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.31.0 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.30.1 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.30.0 lib/rubocop/cop/variable_force/reference.rb