Sha256: 4322059496aabd3a5b6bff8801835d9aa13319e8864a759dd189cbe3773de394

Contents?: true

Size: 1.32 KB

Versions: 10

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

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)
            raise ArgumentError,
                  "Node type must be any of #{VARIABLE_REFERENCE_TYPES}, " \
                  "passed #{node.type}"
          end

          @node = node
          @scope = scope

          super
        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

10 entries across 10 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/variable_force/reference.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/variable_force/reference.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/variable_force/reference.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/variable_force/reference.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/variable_force/reference.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/variable_force/reference.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/variable_force/reference.rb
rubocop-0.47.1 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.47.0 lib/rubocop/cop/variable_force/reference.rb
rubocop-0.46.0 lib/rubocop/cop/variable_force/reference.rb