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|
    if kind(t1) && t1.pos.line == t2.pos.line &&
        t2.pos.column == t1.pos.column + offset(t1) &&
        ![:tRPAREN, :tRBRACK].include?(t2.type)
      add_offense(t1, t1.pos, format(MSG, kind(t1)))
    end
  end
end

#offset(token) ⇒ Object

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(token)
  1
end