module RuboCop::Cop::SpaceBeforePunctuation
Common functionality for cops checking for space before punctuation.
Constants
- MSG
Public Instance Methods
on_new_investigation()
click to toggle source
# File lib/rubocop/cop/mixin/space_before_punctuation.rb, line 12 def on_new_investigation each_missing_space(processed_source.sorted_tokens) do |token, pos_before| add_offense(pos_before, message: format(MSG, token: kind(token))) do |corrector| PunctuationCorrector.remove_space(corrector, pos_before) end end end
Private Instance Methods
each_missing_space(tokens) { |token2, pos_before_punctuation| ... }
click to toggle source
# File lib/rubocop/cop/mixin/space_before_punctuation.rb, line 22 def each_missing_space(tokens) tokens.each_cons(2) do |token1, token2| next unless kind(token2) next unless space_missing?(token1, token2) next if space_required_after?(token1) pos_before_punctuation = range_between(token1.end_pos, token2.begin_pos) yield token2, pos_before_punctuation end end
space_missing?(token1, token2)
click to toggle source
# File lib/rubocop/cop/mixin/space_before_punctuation.rb, line 34 def space_missing?(token1, token2) same_line?(token1, token2) && token2.begin_pos > token1.end_pos end
space_required_after?(token)
click to toggle source
# File lib/rubocop/cop/mixin/space_before_punctuation.rb, line 38 def space_required_after?(token) token.left_curly_brace? && space_required_after_lcurly? end
space_required_after_lcurly?()
click to toggle source
# File lib/rubocop/cop/mixin/space_before_punctuation.rb, line 42 def space_required_after_lcurly? cfg = config.for_cop('Layout/SpaceInsideBlockBraces') style = cfg['EnforcedStyle'] || 'space' style == 'space' end