class RuboCop::Cop::Lint::TopLevelReturnWithArgument

return 1 # 1 is always ignored.
# Detected since Ruby 2.7
@example
always ignored. This is detected automatically since Ruby 2.7.
top-level return statement with an argument, then the argument is
This cop checks for top level return with arguments. If there is a

def ancestors_valid?(return_node)

def ancestors_valid?(return_node)
  prohibited_ancestors = return_node.each_ancestor(:block, :def, :defs)
  prohibited_ancestors.none?
end

def on_return(return_node)

def on_return(return_node)
  add_offense(return_node) if return_node.arguments? && ancestors_valid?(return_node)
end