Class: RuboCop::Cop::PunctuationCorrector

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/correctors/punctuation_corrector.rb

Overview

This auto-corrects punctuation

Class Method Summary collapse

Class Method Details

.add_space(token) ⇒ Object


12
13
14
# File 'lib/rubocop/cop/correctors/punctuation_corrector.rb', line 12

def add_space(token)
  ->(corrector) { corrector.replace(token.pos, token.pos.source + ' ') }
end

.remove_space(space_before) ⇒ Object


8
9
10
# File 'lib/rubocop/cop/correctors/punctuation_corrector.rb', line 8

def remove_space(space_before)
  ->(corrector) { corrector.remove(space_before) }
end

.swap_comma(range) ⇒ Object


16
17
18
19
20
21
22
23
24
25
# File 'lib/rubocop/cop/correctors/punctuation_corrector.rb', line 16

def swap_comma(range)
  return unless range

  lambda do |corrector|
    case range.source
    when ',' then corrector.remove(range)
    else          corrector.insert_after(range, ',')
    end
  end
end