Class: Rubocop::Cop::SpaceAfterColon

Inherits:
Cop
  • Object
show all
Includes:
SpaceAfterCommaEtc
Defined in:
lib/rubocop/cop/space_after_comma_etc.rb

Constant Summary

Constants included from SpaceAfterCommaEtc

Rubocop::Cop::SpaceAfterCommaEtc::MSG

Instance Attribute Summary

Attributes inherited from Cop

#debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods included from SpaceAfterCommaEtc

#inspect

Methods inherited from Cop

#add_offence, cop_name, #has_report?, inherited, #initialize, #inspect, #name, #on_comment

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#kind(token) ⇒ Object



55
56
57
58
59
# File 'lib/rubocop/cop/space_after_comma_etc.rb', line 55

def kind(token)
  case token.type
  when :tLABEL, :tCOLON then 'colon'
  end
end

#offset(token) ⇒ Object

The colon following a label will not appear in the token array. Instad we get a tLABEL token, whose length we use to calculate where we expect a space.



48
49
50
51
52
53
# File 'lib/rubocop/cop/space_after_comma_etc.rb', line 48

def offset(token)
  case token.type
  when :tLABEL then token.text.length + 1
  when :tCOLON then 1
  end
end