lib/rubocop/cop/style/guard_clause.rb in rubocop-1.56.4 vs lib/rubocop/cop/style/guard_clause.rb in rubocop-1.57.0
- old
+ new
@@ -53,10 +53,29 @@
#
# # good
# foo || raise('exception') if something
# ok
#
+ # # bad
+ # define_method(:test) do
+ # if something
+ # work
+ # end
+ # end
+ #
+ # # good
+ # define_method(:test) do
+ # return unless something
+ #
+ # work
+ # end
+ #
+ # # also good
+ # define_method(:test) do
+ # work if something
+ # end
+ #
# @example AllowConsecutiveConditionals: false (default)
# # bad
# def test
# if foo?
# work
@@ -107,9 +126,16 @@
return unless body
check_ending_body(body)
end
alias on_defs on_def
+
+ def on_block(node)
+ return unless node.method?(:define_method) || node.method?(:define_singleton_method)
+
+ on_def(node)
+ end
+ alias on_numblock on_block
def on_if(node)
return if accepted_form?(node)
if (guard_clause = node.if_branch&.guard_clause?)