module RuboCop::Cop::SpaceBeforePunctuation

Common functionality for cops checking for space before punctuation.

Constants

MSG

Public Instance Methods

autocorrect(pos_before_punctuation) click to toggle source
# File lib/rubocop/cop/mixin/space_before_punctuation.rb, line 32
def autocorrect(pos_before_punctuation)
  ->(corrector) { corrector.remove(pos_before_punctuation) }
end
investigate(processed_source) click to toggle source
# File lib/rubocop/cop/mixin/space_before_punctuation.rb, line 10
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
space_required_after_lcurly?() click to toggle source
# File lib/rubocop/cop/mixin/space_before_punctuation.rb, line 26
def space_required_after_lcurly?
  cfg = config.for_cop('Style/SpaceInsideBlockBraces')
  style = cfg['EnforcedStyle'] || 'space'
  style == 'space'
end