Sha256: edc9e3fd6e2276bea701bd78cf4f57610d3fb0042f680bd8675d4cba0461edd3

Contents?: true

Size: 1 KB

Versions: 56

Compression:

Stored size: 1 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.'

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

            next unless 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

56 entries across 37 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-0.86.0 lib/rubocop/cop/style/multiline_block_chain.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/style/multiline_block_chain.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/style/multiline_block_chain.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-0.85.1 lib/rubocop/cop/style/multiline_block_chain.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-0.85.0 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-0.84.0 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-0.83.0 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-0.82.0 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-0.81.0 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-0.80.1 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-0.80.0 lib/rubocop/cop/style/multiline_block_chain.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/style/multiline_block_chain.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-0.79.0 lib/rubocop/cop/style/multiline_block_chain.rb
rubocop-0.78.0 lib/rubocop/cop/style/multiline_block_chain.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/style/multiline_block_chain.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/style/multiline_block_chain.rb