Module: Rubocop::Cop::Style::SpaceAfterCommaEtc

Included in:
SpaceAfterColon, SpaceAfterComma, SpaceAfterSemicolon
Defined in:
lib/rubocop/cop/style/space_after_comma_etc.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/style/space_after_comma_etc.rb', line 26

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

#investigate(processed_source) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/rubocop/cop/style/space_after_comma_etc.rb', line 11

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)
      add_offence(t1, t1.pos, sprintf(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/style/space_after_comma_etc.rb', line 22

def offset(token)
  1
end