Use `next` to skip iteration instead of a condition at the end.
@example
# bad [1, 2].each do |a| if a == 1 do puts a end end # good [1, 2].each do |a| next unless a == 1 puts a end
# File lib/rubocop/cop/style/next.rb, line 29 def on_block(node) method, _, body = *node return unless method.type == :send return if body.nil? _, method_name = *method return unless method?(method_name) return unless ends_with_condition?(body) add_offense(method, :selector, MSG) end
# File lib/rubocop/cop/style/next.rb, line 49 def on_for(node) _, _, body = *node return unless ends_with_condition?(body) add_offense(node, :keyword, MSG) end
# File lib/rubocop/cop/style/next.rb, line 41 def on_while(node) _, body = *node return unless ends_with_condition?(body) add_offense(node, :keyword, MSG) end
Generated with the Darkfish Rdoc Generator 2.