Sha256: 2d619ca30dbefe97761b82e03c5f17ebb65e50335f5e3ce2e639aa85fd3ac6d7

Contents?: true

Size: 842 Bytes

Versions: 4

Compression:

Stored size: 842 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # Here we check if modifier keywords are preceded by a space.
      class SpaceBeforeModifierKeyword < Cop
        MSG = 'Put a space before the modifier keyword.'

        def on_if(node)
          if modifier?(node)
            kw = node.loc.keyword
            b = kw.begin_pos
            left_of_kw = Parser::Source::Range.new(kw.source_buffer, b - 1, b)
            convention(node, left_of_kw) unless left_of_kw.is?(' ')
          end
        end

        alias_method :on_while, :on_if
        alias_method :on_until, :on_if

        private

        def modifier?(node)
          node.loc.respond_to?(:end) && node.loc.end.nil? && !elsif?(node)
        end

        def elsif?(node)
          node.loc.keyword.is?('elsif')
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.14.1 lib/rubocop/cop/style/space_before_modifier_keyword.rb
rubocop-0.14.0 lib/rubocop/cop/style/space_before_modifier_keyword.rb
rubocop-0.13.1 lib/rubocop/cop/style/space_before_modifier_keyword.rb
rubocop-0.13.0 lib/rubocop/cop/style/space_before_modifier_keyword.rb