Parent

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::VariableForce::Assignment

This class represents each assignment of a variable.

Attributes

node[R]
referenced[R]
referenced?[R]
variable[R]

Public Class Methods

new(node, variable) click to toggle source
# File lib/rubocop/cop/variable_force/assignment.rb, line 15
def initialize(node, variable)
  unless VARIABLE_ASSIGNMENT_TYPES.include?(node.type)
    fail ArgumentError,
         "Node type must be any of #{VARIABLE_ASSIGNMENT_TYPES}, "                   "passed #{node.type}"
  end

  @node = node
  @variable = variable
  @referenced = false
end

Public Instance Methods

meta_assignment_node() click to toggle source
# File lib/rubocop/cop/variable_force/assignment.rb, line 66
def meta_assignment_node
  if instance_variable_defined?(:@meta_assignment_node)
    return @meta_assignment_node
  end

  @meta_assignment_node = nil

  return unless parent_node

  if OPERATOR_ASSIGNMENT_TYPES.include?(parent_node.type) &&
     parent_node.children.index(@node) == 0
    return @meta_assignment_node = parent_node
  end

  return unless grantparent_node

  if parent_node.type == MULTIPLE_LEFT_HAND_SIDE_TYPE &&
     grantparent_node.type == MULTIPLE_ASSIGNMENT_TYPE
    return @meta_assignment_node = grantparent_node
  end

  nil
end
multiple_assignment?() click to toggle source
# File lib/rubocop/cop/variable_force/assignment.rb, line 56
def multiple_assignment?
  return false unless meta_assignment_node
  meta_assignment_node.type == MULTIPLE_ASSIGNMENT_TYPE
end
name() click to toggle source
# File lib/rubocop/cop/variable_force/assignment.rb, line 27
def name
  @node.children.first
end
operator() click to toggle source
# File lib/rubocop/cop/variable_force/assignment.rb, line 61
def operator
  assignment_node = meta_assignment_node || @node
  assignment_node.loc.operator.source
end
operator_assignment?() click to toggle source
# File lib/rubocop/cop/variable_force/assignment.rb, line 51
def operator_assignment?
  return false unless meta_assignment_node
  OPERATOR_ASSIGNMENT_TYPES.include?(meta_assignment_node.type)
end
reference!() click to toggle source
# File lib/rubocop/cop/variable_force/assignment.rb, line 35
def reference!
  @referenced = true
end
reference_penetrable?() click to toggle source
# File lib/rubocop/cop/variable_force/assignment.rb, line 43
def reference_penetrable?
  REFERENCE_PENETRABLE_BRANCH_TYPES.include?(branch_type)
end
regexp_named_capture?() click to toggle source
# File lib/rubocop/cop/variable_force/assignment.rb, line 47
def regexp_named_capture?
  @node.type == REGEXP_NAMED_CAPTURE_TYPE
end
scope() click to toggle source
# File lib/rubocop/cop/variable_force/assignment.rb, line 31
def scope
  @variable.scope
end
used?() click to toggle source
# File lib/rubocop/cop/variable_force/assignment.rb, line 39
def used?
  @variable.captured_by_block? || @referenced
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.