Sha256: 349cc30ebcd5a0cfa6115c6f1c1a0c874a078f55c46a3b97d2eac268bc45e709

Contents?: true

Size: 1019 Bytes

Versions: 7

Compression:

Stored size: 1019 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    # Common functionality for cops checking for space before
    # punctuation.
    module SpaceBeforePunctuation
      MSG = 'Space found before %s.'

      def investigate(processed_source)
        processed_source.tokens.each_cons(2) do |t1, t2|
          next unless kind(t2) && t1.pos.line == t2.pos.line &&
            t2.pos.begin_pos > t1.pos.end_pos
          buffer = processed_source.buffer
          pos_before_punctuation = Parser::Source::Range.new(buffer,
                                                             t1.pos.end_pos,
                                                             t2.pos.begin_pos)

          add_offense(pos_before_punctuation,
                      pos_before_punctuation,
                      format(MSG, kind(t2)))
        end
      end

      def autocorrect(pos_before_punctuation)
        @corrections << lambda do |corrector|
          corrector.remove(pos_before_punctuation)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/mixin/space_before_punctuation.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.26.1 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.26.0 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.25.0 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.24.1 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.24.0 lib/rubocop/cop/mixin/space_before_punctuation.rb