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::SINGLE_SPACE_REGEXP, 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



37
38
39
40
41
42
43
44
45
# File 'lib/rubocop/cop/correctors/space_corrector.rb', line 37

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

.empty_corrections(processed_source, corrector, empty_config, left_token, right_token) ⇒ Object



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

def empty_corrections(processed_source, corrector, empty_config,
                      left_token, right_token)
  @processed_source = processed_source
  if offending_empty_space?(empty_config, left_token, right_token)
    range = side_space_range(range: left_token.pos, side: :right)
    corrector.remove(range)
    corrector.insert_after(left_token.pos, ' ')
  elsif offending_empty_no_space?(empty_config, left_token, right_token)
    range = side_space_range(range: left_token.pos, side: :right)
    corrector.remove(range)
  end
end

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



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubocop/cop/correctors/space_corrector.rb', line 25

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