Sha256: e461cb1e1fad0c6f7552a477efc0c9d5e112dfd4f78ecd4d5c85778d98a26dbf

Contents?: true

Size: 994 Bytes

Versions: 49

Compression:

Stored size: 994 Bytes

Contents

# frozen_string_literal: true

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

        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

        def autocorrect(node)
          EmptyLineCorrector.insert_before(node)
        end

        private

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

Version data entries

49 entries across 30 versions & 3 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-0.84.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-0.83.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-0.82.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-0.81.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-0.80.1 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-0.80.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/layout/first_array_element_line_break.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-0.79.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-0.78.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/layout/first_array_element_line_break.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/layout/first_array_element_line_break.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/layout/first_array_element_line_break.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cop/layout/first_array_element_line_break.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/layout/first_array_element_line_break.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/layout/first_array_element_line_break.rb
rubocop-0.77.0 lib/rubocop/cop/layout/first_array_element_line_break.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/layout/first_array_element_line_break.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/layout/first_array_element_line_break.rb