class RubbyCop::Cop::Layout::SpaceAfterColon
Checks for colon (:) not followed by some kind of space. N.B. this cop does not handle spaces after a ternary operator, which are instead handled by Layout/SpaceAroundOperators.
Constants
- MSG
Public Instance Methods
on_kwoptarg(node)
click to toggle source
# File lib/rubbycop/cop/layout/space_after_colon.rb, line 20 def on_kwoptarg(node) # We have no direct reference to the colon source range following an # optional keyword argument's name, so must construct one. colon = node.loc.name.end.resize(1) add_offense(colon, colon) unless followed_by_space?(colon) end
on_pair(node)
click to toggle source
# File lib/rubbycop/cop/layout/space_after_colon.rb, line 12 def on_pair(node) return unless node.colon? colon = node.loc.operator add_offense(colon, colon) unless followed_by_space?(colon) end
Private Instance Methods
autocorrect(range)
click to toggle source
# File lib/rubbycop/cop/layout/space_after_colon.rb, line 34 def autocorrect(range) ->(corrector) { corrector.insert_after(range, ' ') } end
followed_by_space?(colon)
click to toggle source
# File lib/rubbycop/cop/layout/space_after_colon.rb, line 30 def followed_by_space?(colon) colon.source_buffer.source[colon.end_pos] =~ /\s/ end