Sha256: 6699b80960793dbc38e5c0cc571cb66d2d49590b77e61113411059f340778a17

Contents?: true

Size: 891 Bytes

Versions: 1

Compression:

Stored size: 891 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    # Common functionality for cops checking for missing space after
    # punctuation.
    module SpaceAfterPunctuation
      MSG = 'Space missing after %s.'

      def investigate(processed_source)
        processed_source.tokens.each_cons(2) do |t1, t2|
          if kind(t1) && t1.pos.line == t2.pos.line &&
              t2.pos.column == t1.pos.column + offset(t1) &&
              ![:tRPAREN, :tRBRACK].include?(t2.type)
            add_offense(t1, t1.pos, format(MSG, kind(t1)))
          end
        end
      end

      # The normal offset, i.e., the distance from the punctuation
      # token where a space should be, is 1.
      def offset(token)
        1
      end

      def autocorrect(token)
        @corrections << lambda do |corrector|
          corrector.insert_after(token.pos, ' ')
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.20.0 lib/rubocop/cop/mixin/space_after_punctuation.rb