123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::Cop::OrderedGemCorrector

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

Overview

This autocorrects gem dependency order

Class Attribute Summary

Class Method Summary

RangeHelp - Extended

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, move_pos, move_pos_str, range_between, range_by_whole_lines, range_with_comments, range_with_comments_and_lines, range_with_surrounding_comma, range_with_surrounding_space, source_range

OrderedGemNode - Extended

Class Attribute Details

.comments_as_separators (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/correctors/ordered_gem_corrector.rb', line 11

attr_reader :processed_source, :comments_as_separators

.processed_source (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/correctors/ordered_gem_corrector.rb', line 11

attr_reader :processed_source, :comments_as_separators

Class Method Details

.correct(processed_source, node, previous_declaration, comments_as_separators)

[ GitHub ]

  
# File 'lib/rubocop/cop/correctors/ordered_gem_corrector.rb', line 13

def correct(processed_source, node,
            previous_declaration, comments_as_separators)
  @processed_source = processed_source
  @comments_as_separators = comments_as_separators

  current_range = declaration_with_comment(node)
  previous_range = declaration_with_comment(previous_declaration)

  ->(corrector) { corrector.swap(current_range, previous_range) }
end

.declaration_with_comment(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/correctors/ordered_gem_corrector.rb', line 26

def declaration_with_comment(node)
  buffer = processed_source.buffer
  begin_pos = range_by_whole_lines(get_source_range(node, comments_as_separators)).begin_pos
  end_line = buffer.line_for_position(node.source_range.end_pos)
  end_pos = range_by_whole_lines(buffer.line_range(end_line),
                                 include_final_newline: true).end_pos

  range_between(begin_pos, end_pos)
end