class RuboCop::Cop::Style::DefWithParentheses
end
do_something
def Baz.foo
# good
end
do_something
def Baz.foo()
# bad
def foo()=do_something
def foo() do_something end
# good - without parentheses it’s a syntax error
def foo = do_something
# good
def foo() = do_something
# bad
end
do_something
def foo
# good
end
do_something
def foo()
# bad
@example
class/singleton methods are checked.
that does not take any arguments. Both instance and
Checks for parentheses in the definition of a method,
def on_def(node)
def on_def(node) return unless !node.arguments? && (arguments_range = node.arguments.source_range) return if parentheses_required?(node, arguments_range) add_offense(arguments_range) do |corrector| corrector.remove(arguments_range) end end
def parentheses_required?(node, arguments_range)
def parentheses_required?(node, arguments_range) return true if node.single_line? && !node.endless? end_pos = arguments_range.end.end_pos token_after_argument = range_between(end_pos, end_pos + 1).source token_after_argument == '=' end