module RuboCop::Cop::SpaceAfterPunctuation
Common functionality for cops checking for missing space after punctuation.
Constants
- MSG
Public Instance Methods
investigate(processed_source)
click to toggle source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 10 def investigate(processed_source) each_missing_space(processed_source.tokens) do |token| add_offense(token, location: token.pos, message: format(MSG, token: kind(token))) end end
Private Instance Methods
allowed_type?(token)
click to toggle source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 39 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 19 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 50 def offset 1 end
space_forbidden_before_rcurly?()
click to toggle source
# File lib/rubocop/cop/mixin/space_after_punctuation.rb, line 43 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 29 def space_missing?(token1, token2) token1.line == token2.line && 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