Sha256: 5bab6685d4f918d654d70a34e0db47637ff242b41f00419e51b4a7e6bc538643

Contents?: true

Size: 907 Bytes

Versions: 158

Compression:

Stored size: 907 Bytes

Contents

# frozen_string_literal: true

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

158 entries across 157 versions & 17 rubygems

Version Path
rubocop-1.57.0 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.56.4 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.56.3 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.56.2 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
synctera_ruby_sdk-1.1.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
synctera_ruby_sdk-1.1.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
synctera_ruby_sdk-1.1.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
sampero-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.1/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.56.1 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
tursodb-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
synctera_ruby_sdk-1.0.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.56.0 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.55.1 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.55.0 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.54.2 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.54.1/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.54.1/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.52.1/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.54.1 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
rubocop-1.54.0 lib/rubocop/cop/mixin/multiline_element_line_breaks.rb