Sha256: 8ecd688b759f375e900e16d4edf837078ff26f7f02c9a9db9d19ee2b65d29310

Contents?: true

Size: 1.09 KB

Versions: 13

Compression:

Stored size: 1.09 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]
        ).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
        #
        # In this case, the variable `foo` is not explicitly referenced,
        # but it can be considered used implicitly by the `super`.
        def explicit?
          @node.type != ZERO_ARITY_SUPER_TYPE
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/variable_force/reference.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/variable_force/reference.rb
rubocop-0.29.1 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.29.0 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.28.0 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.27.1 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.27.0 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.26.1 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.26.0 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.25.0 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.24.1 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.24.0 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.23.0 lib/rubocop/cop/variable_force/reference.rb