Sha256: 8515b61e06429624c41c076d9c625c8a5f316a4dd24dca51b681bbee2eb1d285

Contents?: true

Size: 947 Bytes

Versions: 8

Compression:

Stored size: 947 Bytes

Contents

# frozen_string_literal: true

# TEAM: backend_infra
# WATCHERS: maxh

module RuboCop
  module Cop
    # Common functionality for checking for a line break before each
    # element in a multi-line collection.
    module MultilineElementLineBreaks
      private

      def check_line_breaks(_node, children, ignore_last: false)
        return if all_on_same_line?(children, ignore_last: ignore_last)

        last_seen_line = -1
        children.each do |child|
          if last_seen_line >= child.first_line
            add_offense(child) { |corrector| EmptyLineCorrector.insert_before(corrector, child) }
          else
            last_seen_line = child.last_line
          end
        end
      end

      def all_on_same_line?(nodes, ignore_last: false)
        return true if nodes.empty?

        return same_line?(nodes.first, nodes.last) if ignore_last

        nodes.first.first_line == nodes.last.last_line
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rubocop-1.45.1 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.45.0 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.44.1 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.44.0 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.43.0 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.42.0 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.41.1 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.41.0 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb