Sha256: bc38971ac2a84d73269554bbb046abd9b920887175e900800e69f37063bb243f

Contents?: true

Size: 784 Bytes

Versions: 84

Compression:

Stored size: 784 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 :sort_with_numblock?, <<~PATTERN
        (numblock
          $(send _ :sort)
          $_arg_count
          $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

84 entries across 84 versions & 4 rubygems

Version Path
harbr-0.1.70 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.69 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.68 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.67 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.66 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.65 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.64 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.63 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.62 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.61 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.60 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.59 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.58 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.57 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.56 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.55 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.54 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.53 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.52 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb
harbr-0.1.50 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.19.1/lib/rubocop/cop/mixin/sort_block.rb