Class: RuboCop::Cop::VariableForce Private

Inherits:
Force
  • Object
show all
Defined in:
lib/rubocop/cop/variable_force.rb,
lib/rubocop/cop/variable_force/scope.rb,
lib/rubocop/cop/variable_force/branch.rb,
lib/rubocop/cop/variable_force/variable.rb,
lib/rubocop/cop/variable_force/reference.rb,
lib/rubocop/cop/variable_force/assignment.rb,
lib/rubocop/cop/variable_force/branchable.rb,
lib/rubocop/cop/variable_force/variable_table.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This force provides a way to track local variables and scopes of Ruby. Cops interact with this force need to override some of the hook methods.

def before_entering_scope(scope, variable_table)
end

def after_entering_scope(scope, variable_table)
end

def before_leaving_scope(scope, variable_table)
end

def after_leaving_scope(scope, variable_table)
end

def before_declaring_variable(variable, variable_table)
end

def after_declaring_variable(variable, variable_table)
end

API:

  • private

Defined Under Namespace

Modules: Branch, Branchable Classes: Assignment, AssignmentReference, Reference, Scope, Variable, VariableReference, VariableTable

Constant Summary collapse

VARIABLE_ASSIGNMENT_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/ClassLength

API:

  • private

:lvasgn
REGEXP_NAMED_CAPTURE_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

:match_with_lvasgn
PATTERN_MATCH_VARIABLE_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

:match_var
VARIABLE_ASSIGNMENT_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

[
  VARIABLE_ASSIGNMENT_TYPE, REGEXP_NAMED_CAPTURE_TYPE, PATTERN_MATCH_VARIABLE_TYPE
].freeze
ARGUMENT_DECLARATION_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

[
  :arg, :optarg, :restarg,
  :kwarg, :kwoptarg, :kwrestarg,
  :blockarg, # This doesn't mean block argument, it's block-pass (&block).
  :shadowarg # This means block local variable (obj.each { |arg; this| }).
].freeze
LOGICAL_OPERATOR_ASSIGNMENT_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

%i[or_asgn and_asgn].freeze
OPERATOR_ASSIGNMENT_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

(LOGICAL_OPERATOR_ASSIGNMENT_TYPES + [:op_asgn]).freeze
MULTIPLE_ASSIGNMENT_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

:masgn
REST_ASSIGNMENT_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

:splat
VARIABLE_REFERENCE_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

:lvar
POST_CONDITION_LOOP_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

%i[while_post until_post].freeze
LOOP_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

(POST_CONDITION_LOOP_TYPES + %i[while until for]).freeze
RESCUE_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

:rescue
ZERO_ARITY_SUPER_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

:zsuper
TWISTED_SCOPE_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

%i[block numblock itblock class sclass defs module].freeze
SCOPE_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

(TWISTED_SCOPE_TYPES + [:def]).freeze
SEND_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

:send
BRANCH_NODES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

%i[if case case_match rescue].freeze

Instance Attribute Summary

Attributes inherited from Force

#cops

Instance Method Summary collapse

Methods inherited from Force

all, force_name, inherited, #initialize, #name, #run_hook

Constructor Details

This class inherits a constructor from RuboCop::Cop::Force

Instance Method Details

#investigate(processed_source) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Starting point.

API:

  • private



81
82
83
84
85
86
87
88
# File 'lib/rubocop/cop/variable_force.rb', line 81

def investigate(processed_source)
  root_node = processed_source.ast
  return unless root_node

  variable_table.push_scope(root_node)
  process_node(root_node)
  variable_table.pop_scope
end

#process_node(node) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



90
91
92
93
94
# File 'lib/rubocop/cop/variable_force.rb', line 90

def process_node(node)
  method_name = node_handler_method_name(node)
  retval = send(method_name, node) if method_name
  process_children(node) unless retval == :skip_children
end

#variable_tableObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



76
77
78
# File 'lib/rubocop/cop/variable_force.rb', line 76

def variable_table
  @variable_table ||= VariableTable.new(self)
end