Sha256: 72e0f3fa849e247e8972d30b31d1ad6ec84f0702111b2fd169dfced10ed13e40

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # Checks for chaining of a block after another block that spans
      # multiple lines.
      #
      # @example
      #
      #   # bad
      #   Thread.list.select do |t|
      #     t.alive?
      #   end.map do |t|
      #     t.object_id
      #   end
      #
      #   # good
      #   alive_threads = Thread.list.select do |t|
      #     t.alive?
      #   end
      #   alive_threads.map do |t|
      #     t.object_id
      #   end
      class MultilineBlockChain < Base
        include RangeHelp

        MSG = 'Avoid multi-line chains of blocks.'

        def on_block(node)
          node.send_node.each_node(:send, :csend) do |send_node|
            receiver = send_node.receiver

            next unless receiver&.any_block_type? && receiver.multiline?

            range = range_between(receiver.loc.end.begin_pos, node.send_node.source_range.end_pos)

            add_offense(range)

            # Done. If there are more blocks in the chain, they will be
            # found by subsequent calls to on_block.
            break
          end
        end

        alias on_numblock on_block
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
siteimprove_api_client-1.0.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.73.1/lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-1.73.1 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-1.73.0 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-1.72.2 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-1.72.1 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-1.72.0 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-1.71.2 lib/rubocop/cop/style/multiline_block_chain.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rubocop-1.71.1/lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-1.71.1 lib/rubocop/cop/style/multiline_block_chain.rb