Sha256: 601dd44e36115c42b347c37ced1dd6a14e283f3e9e1ea68e8881edce99928595

Contents?: true

Size: 822 Bytes

Versions: 5

Compression:

Stored size: 822 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 hash.
      #
      # @example
      #
      #     # bad
      #     { a: 1,
      #       b: 2}
      #
      #     # good
      #     {
      #       a: 1,
      #       b: 2 }
      class FirstHashElementLineBreak < Cop
        include FirstElementLineBreak

        MSG = 'Add a line break before the first element of a ' \
              'multi-line hash.'.freeze

        def on_hash(node)
          # node.loc.begin tells us whether the hash opens with a {
          # If it doesn't, Style/FirstMethodArgumentLineBreak will handle it
          check_children_line_break(node, node.children) if node.loc.begin
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-0.52.0 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.51.0 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.50.0 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.49.1 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.49.0 lib/rubocop/cop/layout/first_hash_element_line_break.rb