Sha256: deacb9f991af7151e97d61c1e24ffe9716caa8f191639a3e482b9178f3ed853f
Contents?: true
Size: 1.04 KB
Versions: 14
Compression:
Stored size: 1.04 KB
Contents
# encoding: utf-8 # frozen_string_literal: true module RuboCop module Cop module Style # Checks for uses of `do` in multi-line `while/until` statements. class WhileUntilDo < Cop def on_while(node) handle(node) end def on_until(node) handle(node) end def handle(node) length = node.source.lines.to_a.size return unless length > 1 return unless node.loc.begin && node.loc.begin.is?('do') add_offense(node, :begin, error_message(node.type)) end private def error_message(node_type) format('Do not use `do` with multi-line `%s`.', node_type) end def autocorrect(node) condition_node, = *node end_of_condition_range = condition_node.source_range.end do_range = node.loc.begin whitespaces_and_do_range = end_of_condition_range.join(do_range) ->(corrector) { corrector.remove(whitespaces_and_do_range) } end end end end end
Version data entries
14 entries across 14 versions & 2 rubygems