Sha256: a7af019abb728d0e6bdd99f3e08feac84e7e7d05ceb7b75ddd1dde2701e88ee5

Contents?: true

Size: 908 Bytes

Versions: 26

Compression:

Stored size: 908 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Layout
      # Checks for a line break before the first element in a
      # multi-line array.
      #
      # @example
      #
      #     # bad
      #     [ :a,
      #       :b]
      #
      #     # good
      #     [
      #       :a,
      #       :b]
      #
      class FirstArrayElementLineBreak < Base
        include FirstElementLineBreak
        extend AutoCorrector

        MSG = 'Add a line break before the first element of a multi-line array.'

        def on_array(node)
          return if !node.loc.begin && !assignment_on_same_line?(node)

          check_children_line_break(node, node.children)
        end

        private

        def assignment_on_same_line?(node)
          source = node.source_range.source_line[0...node.loc.column]
          /\s*=\s*$/.match?(source)
        end
      end
    end
  end
end

Version data entries

26 entries across 22 versions & 3 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/first_array_element_line_break.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/first_array_element_line_break.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/first_array_element_line_break.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/layout/first_array_element_line_break.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/first_array_element_line_break.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/cop/layout/first_array_element_line_break.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/layout/first_array_element_line_break.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/first_array_element_line_break.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-1.40.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-1.39.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-1.38.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-1.37.1 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-1.37.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-1.36.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-1.35.1 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-1.35.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-1.34.1 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-1.34.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-1.33.0 lib/rubocop/cop/layout/first_array_element_line_break.rb