Sha256: 813bd736c830dd51a20f5410f007f8405a1eefa2dec7a2d3a67480141c593f0e

Contents?: true

Size: 784 Bytes

Versions: 12

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
          $(call _ :sort)
          (args (arg $_a) (arg $_b))
          $send)
      PATTERN

      def_node_matcher :sort_with_numblock?, <<~PATTERN
        (numblock
          $(call _ :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

12 entries across 12 versions & 4 rubygems

Version Path
rubocop-performance-1.23.1 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.23.0 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.22.1 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.22.0 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.21.1 lib/rubocop/cop/mixin/sort_block.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-performance-1.21.0/lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.21.0 lib/rubocop/cop/mixin/sort_block.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.20.2/lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.20.2 lib/rubocop/cop/mixin/sort_block.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/rubocop-performance-1.20.1/lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.20.1 lib/rubocop/cop/mixin/sort_block.rb
rubocop-performance-1.20.0 lib/rubocop/cop/mixin/sort_block.rb