Sha256: 24d2bc0ad50e2c4e3c9978d9c8c2fe7eb629bc2bb1d7981cb150688fbdfddbae

Contents?: true

Size: 903 Bytes

Versions: 4

Compression:

Stored size: 903 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # Checks for while and until statements that would fit on one line
      # if written as a modifier while/until.
      # The maximum line length is configurable.
      class WhileUntilModifier < Cop
        include StatementModifier

        def investigate(processed_source)
          return unless processed_source.ast
          on_node([:while, :until], processed_source.ast) do |node|
            # discard modifier while/until
            next unless node.loc.end

            if check(node, processed_source.comments)
              add_offense(node, :keyword,
                          message(node.loc.keyword.source))
            end
          end
        end

        private

        def message(keyword)
          "Favor modifier `#{keyword}` usage when having a single-line body."
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.22.0 lib/rubocop/cop/style/while_until_modifier.rb
rubocop-0.21.0 lib/rubocop/cop/style/while_until_modifier.rb
rubocop-0.20.1 lib/rubocop/cop/style/while_until_modifier.rb
rubocop-0.20.0 lib/rubocop/cop/style/while_until_modifier.rb