Method: RuboCop::Cop::Lint::SafeNavigationConsistency#on_and

Defined in:
lib/rubocop/cop/lint/safe_navigation_consistency.rb

#on_and(node) ⇒ Object Also known as: on_or


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rubocop/cop/lint/safe_navigation_consistency.rb', line 48

def on_and(node)
  all_operands = collect_operands(node, [])
  operand_groups = all_operands.group_by { |operand| receiver_name_as_key(operand, +'') }

  operand_groups.each_value do |grouped_operands|
    next unless (dot_op, begin_of_rest_operands = find_consistent_parts(grouped_operands))

    rest_operands = grouped_operands[begin_of_rest_operands..]
    rest_operands.each do |operand|
      next if already_appropriate_call?(operand, dot_op)

      register_offense(operand, dot_op)
    end
  end
end