Sha256: 34de2fc70eb12bc33b38100ede9aa2377007365cf5af6e6118fc2fb9d36724f6

Contents?: true

Size: 1 KB

Versions: 7

Compression:

Stored size: 1 KB

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 & 1 rubygems

Version Path
rubocop-0.30.1 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.30.0 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.29.1 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.29.0 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.28.0 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.27.1 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.27.0 lib/rubocop/cop/mixin/space_before_punctuation.rb