123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::Cop::SpaceCorrector

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Inherits: Object
Defined in: lib/rubocop/cop/correctors/space_corrector.rb

Overview

This autocorrects whitespace

Class Attribute Summary

Class Method Summary

Class Attribute Details

.processed_source (readonly)

[ GitHub ]

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

attr_reader :processed_source

Class Method Details

.add_space(processed_source, corrector, left_token, right_token)

[ GitHub ]

  
# File 'lib/rubocop/cop/correctors/space_corrector.rb', line 36

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

  corrector.insert_before(right_token.pos, ' ')
end

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

[ GitHub ]

  
# 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
  range = range_between(left_token.end_pos, right_token.begin_pos)
  if offending_empty_space?(empty_config, left_token, right_token)
    corrector.remove(range)
    corrector.insert_after(left_token.pos, ' ')
  elsif offending_empty_no_space?(empty_config, left_token, right_token)
    corrector.remove(range)
  end
end

.remove_space(processed_source, corrector, left_token, right_token)

[ GitHub ]

  
# File 'lib/rubocop/cop/correctors/space_corrector.rb', line 24

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