module RuboCop::Cop::SpaceAfterPunctuation
Common functionality for cops checking for missing space after punctuation.
Constants
- MSG
Public Instance Methods
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
Source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 38 def allowed_type?(token) %i[tRPAREN tRBRACK tPIPE tSTRING_DEND].include?(token.type) end
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
Source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 49 def offset 1 end
The normal offset, i.e., the distance from the punctuation token where a space should be, is 1.
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
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
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