Class: RuboCop::Cop::SpaceCorrector

Inherits:
Object
  • Object
show all
Extended by:
SurroundingSpace
Defined in:
lib/rubocop/cop/correctors/space_corrector.rb

Overview

This auto-corrects whitespace

Constant Summary

Constants included from SurroundingSpace

RuboCop::Cop::SurroundingSpace::NO_SPACE_COMMAND, RuboCop::Cop::SurroundingSpace::SPACE_COMMAND

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.processed_sourceObject (readonly)

Returns the value of attribute processed_source.



10
11
12
# File 'lib/rubocop/cop/correctors/space_corrector.rb', line 10

def processed_source
  @processed_source
end

Class Method Details

.add_space(processed_source, corrector, left_token, right_token) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/rubocop/cop/correctors/space_corrector.rb', line 23

def add_space(processed_source, corrector, left_token, right_token)
  @processed_source = processed_source
  unless left_token.space_after?
    corrector.insert_after(left_token.pos, ' ')
  end
  return if right_token.space_before?
  corrector.insert_before(right_token.pos, ' ')
end

.remove_space(processed_source, corrector, left_token, right_token) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/rubocop/cop/correctors/space_corrector.rb', line 12

def remove_space(processed_source, corrector, left_token, right_token)
  @processed_source = processed_source
  if left_token.space_after?
    range = side_space_range(range: left_token.pos, side: :right)
    corrector.remove(range)
  end
  return unless right_token.space_before?
  range = side_space_range(range: right_token.pos, side: :left)
  corrector.remove(range)
end