Sha256: ff98bb7cb98d1234b10a9d1eeb84c016119131f967f49a0c5bd2a38ce28cd061

Contents?: true

Size: 1.19 KB

Versions: 150

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # This autocorrects gem dependency order
    class OrderedGemCorrector
      class << self
        include OrderedGemNode
        include RangeHelp

        attr_reader :processed_source, :comments_as_separators

        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

        private

        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
      end
    end
  end
end

Version data entries

150 entries across 149 versions & 15 rubygems

Version Path
rubocop-1.68.0 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.67.0 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.66.1 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.66.0 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.65.1 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.65.0 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.64.1 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.63.4 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.63.3 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.63.2 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.63.1 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.63.0 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.62.1/lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.62.1 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.62.0 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
rubocop-1.61.0 lib/rubocop/cop/correctors/ordered_gem_corrector.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/correctors/ordered_gem_corrector.rb