module RuboCop::Cop::SpaceAfterPunctuation
Common functionality for cops checking for missing space after punctuation.
Constants
- MSG
Public Instance Methods
on_new_investigation()
click to toggle source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 10 def on_new_investigation each_missing_space(processed_source.tokens) do |token| add_offense(token.pos, message: format(MSG, token: kind(token))) do |corrector| PunctuationCorrector.add_space(corrector, token) end end end
Private Instance Methods
allowed_type?(token)
click to toggle source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 38 def allowed_type?(token) %i[tRPAREN tRBRACK tPIPE].include?(token.type) end
each_missing_space(tokens) { |token1| ... }
click to toggle source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 20 def each_missing_space(tokens) tokens.each_cons(2) do |token1, token2| next unless kind(token1) next unless space_missing?(token1, token2) next unless space_required_before?(token2) yield token1 end end
offset()
click to toggle source
The normal offset, i.e., the distance from the punctuation token where a space should be, is 1.
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 49 def offset 1 end
space_forbidden_before_rcurly?()
click to toggle source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 42 def space_forbidden_before_rcurly? style = space_style_before_rcurly style == 'no_space' end
space_missing?(token1, token2)
click to toggle source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 30 def space_missing?(token1, token2) same_line?(token1, token2) && token2.column == token1.column + offset end
space_required_before?(token)
click to toggle source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 34 def space_required_before?(token) !(allowed_type?(token) || (token.right_curly_brace? && space_forbidden_before_rcurly?)) end