Class: RuboCop::Cop::VariableForce
- 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 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 =
rubocop:disable Metrics/ClassLength
:lvasgn
- REGEXP_NAMED_CAPTURE_TYPE =
:match_with_lvasgn
- VARIABLE_ASSIGNMENT_TYPES =
[VARIABLE_ASSIGNMENT_TYPE, REGEXP_NAMED_CAPTURE_TYPE].freeze
- ARGUMENT_DECLARATION_TYPES =
[ :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 =
%i[or_asgn and_asgn].freeze
- OPERATOR_ASSIGNMENT_TYPES =
(LOGICAL_OPERATOR_ASSIGNMENT_TYPES + [:op_asgn]).freeze
- MULTIPLE_ASSIGNMENT_TYPE =
:masgn
- VARIABLE_REFERENCE_TYPE =
:lvar
- POST_CONDITION_LOOP_TYPES =
%i[while_post until_post].freeze
- LOOP_TYPES =
(POST_CONDITION_LOOP_TYPES + %i[while until for]).freeze
- RESCUE_TYPE =
:rescue
- ZERO_ARITY_SUPER_TYPE =
:zsuper
- TWISTED_SCOPE_TYPES =
%i[block class sclass defs].freeze
- SCOPE_TYPES =
(TWISTED_SCOPE_TYPES + %i[module def]).freeze
- SEND_TYPE =
:send
Instance Attribute Summary
Attributes inherited from Force
Instance Method Summary collapse
-
#investigate(processed_source) ⇒ Object
Starting point.
- #process_node(node) ⇒ Object
- #variable_table ⇒ Object
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
Starting point.
75 76 77 78 79 80 81 82 |
# File 'lib/rubocop/cop/variable_force.rb', line 75 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
84 85 86 87 88 |
# File 'lib/rubocop/cop/variable_force.rb', line 84 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_table ⇒ Object
70 71 72 |
# File 'lib/rubocop/cop/variable_force.rb', line 70 def variable_table @variable_table ||= VariableTable.new(self) end |