Sha256: 5c49d6248f337f962cd58bcd17d7446a8874b3b0ff795831ff3917066ccc7000

Contents?: true

Size: 802 Bytes

Versions: 9

Compression:

Stored size: 802 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 on_while(node)
          check(node)
        end

        def on_until(node)
          check(node)
        end

        private

        def check(node)
          return unless node.loc.end
          return unless fit_within_line_as_modifier_form?(node)
          add_offense(node, :keyword, message(node.loc.keyword.source))
        end

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

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/while_until_modifier.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/while_until_modifier.rb
rubocop-0.29.1 lib/rubocop/cop/style/while_until_modifier.rb
rubocop-0.29.0 lib/rubocop/cop/style/while_until_modifier.rb
rubocop-0.28.0 lib/rubocop/cop/style/while_until_modifier.rb
rubocop-0.27.1 lib/rubocop/cop/style/while_until_modifier.rb
rubocop-0.27.0 lib/rubocop/cop/style/while_until_modifier.rb
rubocop-0.26.1 lib/rubocop/cop/style/while_until_modifier.rb
rubocop-0.26.0 lib/rubocop/cop/style/while_until_modifier.rb