Sha256: 8f95023273cb0b8b39d14650b355ba8536b7d673095160960db2d89f774b8897

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 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 &&
                      !(t1.type == :tLCURLY && space_required_after_lcurly?)
          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 space_required_after_lcurly?
        cfg = config.for_cop('Style/SpaceInsideBlockBraces')
        style = cfg['Enabled'] ? cfg['EnforcedStyle'] : 'space'
        style == 'space'
      end

      def autocorrect(pos_before_punctuation)
        ->(corrector) { corrector.remove(pos_before_punctuation) }
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.35.0 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.34.2 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.34.1 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.34.0 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.33.0 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.32.1 lib/rubocop/cop/mixin/space_before_punctuation.rb
rubocop-0.32.0 lib/rubocop/cop/mixin/space_before_punctuation.rb