Sha256: 7367a0d186d0116f837d3595abd570e3abcb8de1c5aa8eba0d9339e5598a6972

Contents?: true

Size: 1.06 KB

Versions: 6562

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Common functionality for checking for a line break before the first
    # element in a multi-line collection.
    module FirstElementLineBreak
      private

      def check_method_line_break(node, children)
        return if children.empty?

        return unless method_uses_parens?(node, children.first)

        check_children_line_break(node, children)
      end

      def method_uses_parens?(node, limit)
        source = node.source_range.source_line[0...limit.loc.column]
        source =~ /\s*\(\s*$/
      end

      def check_children_line_break(node, children, start = node)
        return if children.size < 2

        line = start.first_line

        min = first_by_line(children)
        return if line != min.first_line

        max = last_by_line(children)
        return if line == max.last_line

        add_offense(min)
      end

      def first_by_line(nodes)
        nodes.min_by(&:first_line)
      end

      def last_by_line(nodes)
        nodes.max_by(&:last_line)
      end
    end
  end
end

Version data entries

6,562 entries across 6,537 versions & 29 rubygems

Version Path
cybrid_api_bank_ruby-0.122.57 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_organization_ruby-0.122.57 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_id_ruby-0.122.54 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_bank_ruby-0.122.54 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_organization_ruby-0.122.54 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_bank_ruby-0.122.53 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_organization_ruby-0.122.53 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_id_ruby-0.122.53 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_id_ruby-0.122.52 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_bank_ruby-0.122.52 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_organization_ruby-0.122.52 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_bank_ruby-0.122.51 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_organization_ruby-0.122.51 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_id_ruby-0.122.51 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_bank_ruby-0.122.49 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_id_ruby-0.122.49 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_organization_ruby-0.122.49 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_bank_ruby-0.122.48 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_id_ruby-0.122.48 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb
cybrid_api_organization_ruby-0.122.48 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/first_element_line_break.rb