Sha256: 34bfae4e8042378e8a8f50fd65c572ed71b297af0a1db3850b5fa642a9c2cb63
Contents?: true
Size: 1.15 KB
Versions: 38
Compression:
Stored size: 1.15 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 # # # 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) 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(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
38 entries across 38 versions & 6 rubygems