Sha256: 8a1beb891e1ea06fb669426276c666dcd588bdfadf5c4ce3d0617152a637e4ad

Contents?: true

Size: 630 Bytes

Versions: 33

Compression:

Stored size: 630 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Common functionality for cops checking `Enumerable#sort` blocks.
    module SortBlock
      extend NodePattern::Macros
      include RangeHelp

      def_node_matcher :sort_with_block?, <<~PATTERN
        (block
          $(send _ :sort)
          (args (arg $_a) (arg $_b))
          $send)
      PATTERN

      def_node_matcher :replaceable_body?, <<~PATTERN
        (send (lvar %1) :<=> (lvar %2))
      PATTERN

      private

      def sort_range(send, node)
        range_between(send.loc.selector.begin_pos, node.loc.end.end_pos)
      end
    end
  end
end

Version data entries

33 entries across 31 versions & 4 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-performance-1.14.3/lib/rubocop/cop/mixin/sort_block.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-performance-1.14.3/lib/rubocop/cop/mixin/sort_block.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-performance-1.14.3/lib/rubocop/cop/mixin/sort_block.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-performance-1.13.3/lib/rubocop/cop/mixin/sort_block.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-performance-1.14.3/lib/rubocop/cop/mixin/sort_block.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-performance-1.13.3/lib/rubocop/cop/mixin/sort_block.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-performance-1.14.3/lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.14.3 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.14.2 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.14.1 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.14.0 lib/rubocop/cop/mixin/sort_block.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-performance-1.13.3/lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.13.3 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.13.2 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.13.1 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.13.0 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.12.0 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.11.5 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.11.4 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.11.3 lib/rubocop/cop/mixin/sort_block.rb