Sha256: 080e3b2657b290607546eb343637347d7089df5cc3d403dddbe823194e2ff49e

Contents?: true

Size: 1.02 KB

Versions: 6789

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for chaining of a block after another block that spans
      # multiple lines.
      #
      # @example
      #
      #   Thread.list.find_all do |t|
      #     t.alive?
      #   end.map do |t|
      #     t.object_id
      #   end
      class MultilineBlockChain < Cop
        include RangeHelp

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

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

            next unless receiver && receiver.block_type? && receiver.multiline?

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

            add_offense(nil, location: range)

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

Version data entries

6,789 entries across 6,783 versions & 25 rubygems

Version Path
cybrid_api_bank_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_id_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_organization_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_bank_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_id_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_organization_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_bank_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_organization_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_id_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
ory-client-1.16.2 vendor/bundle/ruby/3.1.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
avalara_sdk-24.12.2 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_bank_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_organization_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_id_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_bank_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_id_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_organization_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
ory-client-1.16.1 vendor/bundle/ruby/3.1.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
ory-client-1.16.0 vendor/bundle/ruby/3.1.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb
cybrid_api_bank_ruby-0.123.143 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/multiline_block_chain.rb