module RuboCop::Cop::SpaceAfterPunctuation

Common functionality for cops checking for missing space after punctuation.

Constants

MSG

Public Instance Methods

autocorrect(token) click to toggle source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 33
def autocorrect(token)
  ->(corrector) { corrector.replace(token.pos, token.pos.source + ' ') }
end
investigate(processed_source) click to toggle source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 10
def investigate(processed_source)
  processed_source.tokens.each_cons(2) do |t1, t2|
    next unless kind(t1) && t1.pos.line == t2.pos.line &&
                t2.pos.column == t1.pos.column + offset &&
                ![:tRPAREN, :tRBRACK, :tPIPE].include?(t2.type) &&
                !(t2.type == :tRCURLY && space_forbidden_before_rcurly?)

    add_offense(t1, t1.pos, format(MSG, kind(t1)))
  end
end
offset() click to toggle source

The normal offset, i.e., the distance from the punctuation token where a space should be, is 1.

# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 29
def offset
  1
end
space_forbidden_before_rcurly?() click to toggle source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 21
def space_forbidden_before_rcurly?
  cfg = config.for_cop('Style/SpaceInsideBlockBraces')
  style = cfg['EnforcedStyle'] || 'space'
  style == 'no_space'
end