class RuboCop::Cop::Style::WhileUntilDo
Checks for uses of `do` in multi-line `while/until` statements.
@example
# bad while x.any? do do_something(x.pop) end # good while x.any? do_something(x.pop) end
@example
# bad until x.empty? do do_something(x.pop) end # good until x.empty? do_something(x.pop) end
Constants
- MSG
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/style/while_until_do.rb, line 49 def autocorrect(node) do_range = node.condition.source_range.end.join(node.loc.begin) lambda do |corrector| corrector.remove(do_range) end end
handle(node)
click to toggle source
# File lib/rubocop/cop/style/while_until_do.rb, line 42 def handle(node) return unless node.multiline? && node.do? add_offense(node, location: :begin, message: format(MSG, keyword: node.keyword)) end
on_until(node)
click to toggle source
# File lib/rubocop/cop/style/while_until_do.rb, line 38 def on_until(node) handle(node) end
on_while(node)
click to toggle source
# File lib/rubocop/cop/style/while_until_do.rb, line 34 def on_while(node) handle(node) end