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

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

: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.

: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.

: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.

[
  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.

[
  :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.

%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.

(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.

: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.

: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.

: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.

%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.

(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.

: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.

: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.

%i[block numblock 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.

(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.

:send

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.



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

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.



88
89
90
91
92
# File 'lib/rubocop/cop/variable_force.rb', line 88

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.



74
75
76
# File 'lib/rubocop/cop/variable_force.rb', line 74

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