Sha256: b173f04fab3cec3c344ec24249be38a9729026a6e562b7688a95324f29b8c458

Contents?: true

Size: 959 Bytes

Versions: 10

Compression:

Stored size: 959 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module SpaceAfterCommaEtc
      ERROR_MESSAGE = 'Space missing after %s.'

      def inspect(file, source, tokens, sexp)
        tokens.each_index do |ix|
          t = tokens[ix]
          if kind(t) && !whitespace?(tokens[ix + 1])
            add_offence(:convention, t.pos.lineno, ERROR_MESSAGE % kind(t))
          end
        end
      end
    end

    class SpaceAfterComma < Cop
      include SpaceAfterCommaEtc
      def kind(token)
        'comma' if token.type == :on_comma
      end
    end

    class SpaceAfterSemicolon < Cop
      include SpaceAfterCommaEtc
      def kind(token)
        'semicolon' if token.type == :on_semicolon
      end
    end

    class SpaceAfterColon < Cop
      include SpaceAfterCommaEtc
      def kind(token)
        case token.type
        when :on_label then 'colon'
        when :on_op    then 'colon' if token.text == ':'
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rubocop-0.4.6 lib/rubocop/cop/space_after_comma_etc.rb
rubocop-0.4.5 lib/rubocop/cop/space_after_comma_etc.rb
rubocop-0.4.4 lib/rubocop/cop/space_after_comma_etc.rb
rubocop-0.4.3 lib/rubocop/cop/space_after_comma_etc.rb
rubocop-0.4.2 lib/rubocop/cop/space_after_comma_etc.rb
rubocop-0.4.1 lib/rubocop/cop/space_after_comma_etc.rb
rubocop-0.4.0 lib/rubocop/cop/space_after_comma_etc.rb
rubocop-0.3.2 lib/rubocop/cop/space_after_comma_etc.rb
rubocop-0.3.1 lib/rubocop/cop/space_after_comma_etc.rb
rubocop-0.3.0 lib/rubocop/cop/space_after_comma_etc.rb