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

SurroundingSpace - Extended

RangeHelp - Included

add_range,
arguments_range

A range containing the first to the last argument of a method call or method definition.

column_offset_between,
contents_range

A range containing only the contents of a literal with delimiters (e.g.

directions,
effective_column

Returns the column attribute of the range, except if the range is on the first line and there’s a byte order mark at the beginning of that line, in which case 1 is subtracted from the column value.

final_pos

rubocop:disable-next Metrics/ParameterLists.

move_pos, move_pos_str, range_between, range_by_whole_lines,
range_for_statement_removal

Returns the range to remove a statement: its whole lines, including a trailing comment and the final newline, when no other code shares them, and otherwise the range itself with the spaces after it.

range_with_comments, range_with_comments_and_lines, range_with_surrounding_comma, range_with_surrounding_space, source_range

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