Module: RuboCop::Cop::SpaceAfterPunctuation

Included in:
RuboCop::Cop::Style::SpaceAfterComma, RuboCop::Cop::Style::SpaceAfterSemicolon
Defined in:
lib/rubocop/cop/mixin/space_after_punctuation.rb

Overview

Common functionality for cops checking for missing space after punctuation.

Constant Summary collapse

MSG =
'Space missing after %s.'

Instance Method Summary collapse

Instance Method Details

#autocorrect(token) ⇒ Object



26
27
28
29
30
# File 'lib/rubocop/cop/mixin/space_after_punctuation.rb', line 26

def autocorrect(token)
  @corrections << lambda do |corrector|
    corrector.replace(token.pos, token.pos.source + ' ')
  end
end

#investigate(processed_source) ⇒ Object



10
11
12
13
14
15
16
17
18
# 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].include?(t2.type)

    add_offense(t1, t1.pos, format(MSG, kind(t1)))
  end
end

#offsetObject

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



22
23
24
# File 'lib/rubocop/cop/mixin/space_after_punctuation.rb', line 22

def offset
  1
end