class RuboCop::Cop::Lint::SafeNavigationChain

x&.foo || bar
x&.foo&.bar
# good

@example

x&.foo[bar]
x&.foo + bar
x&.foo.bar
# bad
@example
This cop checks for the problem outlined above.
safe navigation operator after a safe navigation operator.
navigation operator, it raises NoMethodError. We should use a
nil. If you chain an ordinary method call after a safe
The safe navigation operator returns nil if the receiver is

def method_chain(node)

def method_chain(node)
  chain = node
  chain = chain.parent if chain.send_type? && chain.parent&.call_type?
  chain
end

def on_send(node)

def on_send(node)
  bad_method?(node) do |safe_nav, method|
    return if nil_methods.include?(method)
    method_chain = method_chain(node)
    location =
      Parser::Source::Range.new(node.source_range.source_buffer,
                                safe_nav.source_range.end_pos,
                                method_chain.source_range.end_pos)
    add_offense(location)
  end
end