lib/rubocop/cop/style/space_after_colon.rb in rubocop-0.23.0 vs lib/rubocop/cop/style/space_after_colon.rb in rubocop-0.24.0
- old
+ new
@@ -9,21 +9,25 @@
MSG = 'Space missing after colon.'
def on_pair(node)
oper = node.loc.operator
- return unless oper.is?(':') &&
- oper.source_buffer.source[oper.end_pos] =~ /\S/
+ return unless oper.is?(':') && followed_by_space?(oper)
add_offense(oper, oper)
end
def on_if(node)
return unless ternary_op?(node)
+
colon = node.loc.colon
- return unless colon.source_buffer.source[colon.end_pos] =~ /\S/
+ return unless followed_by_space?(colon)
add_offense(colon, colon)
+ end
+
+ def followed_by_space?(colon)
+ colon.source_buffer.source[colon.end_pos] =~ /\S/
end
def autocorrect(range)
@corrections << lambda do |corrector|
corrector.insert_after(range, ' ')