class RuboCop::Cop::Lint::TopLevelReturnWithArgument

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

def on_return(return_node)

def on_return(return_node)
  return unless top_level_return_with_any_argument?(return_node)
  add_offense(return_node) do |corrector|
    remove_arguments(corrector, return_node)
  end
end

def remove_arguments(corrector, return_node)

def remove_arguments(corrector, return_node)
  corrector.replace(return_node, 'return')
end

def top_level_return?(return_node)

defs type.
top-level return node's ancestors should not be of block, def, or
This cop works by validating the ancestors of the return node. A
def top_level_return?(return_node)
  return_node.each_ancestor(:block, :def, :defs).none?
end

def top_level_return_with_any_argument?(return_node)

def top_level_return_with_any_argument?(return_node)
  top_level_return?(return_node) && return_node.arguments?
end