lib/rubocop/cop/mixin/space_before_punctuation.rb in rubocop-0.51.0 vs lib/rubocop/cop/mixin/space_before_punctuation.rb in rubocop-0.52.0

- old
+ new

@@ -3,47 +3,47 @@ module RuboCop module Cop # Common functionality for cops checking for space before # punctuation. module SpaceBeforePunctuation - MSG = 'Space found before %s.'.freeze + MSG = 'Space found before %<token>s.'.freeze def investigate(processed_source) each_missing_space(processed_source.tokens) do |token, pos_before| add_offense(pos_before, location: pos_before, - message: format(MSG, kind(token))) + message: format(MSG, token: kind(token))) end end + def autocorrect(pos_before_punctuation) + ->(corrector) { corrector.remove(pos_before_punctuation) } + end + def each_missing_space(tokens) tokens.each_cons(2) do |t1, t2| next unless kind(t2) next unless space_missing?(t1, t2) next if space_required_after?(t1) - pos_before_punctuation = range_between(t1.pos.end_pos, - t2.pos.begin_pos) + pos_before_punctuation = range_between(t1.end_pos, + t2.begin_pos) yield t2, pos_before_punctuation end end def space_missing?(t1, t2) - t1.pos.line == t2.pos.line && t2.pos.begin_pos > t1.pos.end_pos + t1.line == t2.line && t2.begin_pos > t1.end_pos end def space_required_after?(token) - token.type == :tLCURLY && space_required_after_lcurly? + token.left_curly_brace? && space_required_after_lcurly? end def space_required_after_lcurly? cfg = config.for_cop('Layout/SpaceInsideBlockBraces') style = cfg['EnforcedStyle'] || 'space' style == 'space' - end - - def autocorrect(pos_before_punctuation) - ->(corrector) { corrector.remove(pos_before_punctuation) } end end end end