Sha256: cd87956297627df05bd35985744eb830e8fe1ae9142535af1fca066fdd987e1d

Contents?: true

Size: 907 Bytes

Versions: 60

Compression:

Stored size: 907 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.'

        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

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

Version data entries

60 entries across 41 versions & 5 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_hash_element_line_break.rb
rubocop-0.89.1 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.89.0 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.88.0 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.87.1 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.87.0 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.86.0 lib/rubocop/cop/layout/first_hash_element_line_break.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/layout/first_hash_element_line_break.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.85.1 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.85.0 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.84.0 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.83.0 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.82.0 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.81.0 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.80.1 lib/rubocop/cop/layout/first_hash_element_line_break.rb
rubocop-0.80.0 lib/rubocop/cop/layout/first_hash_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_hash_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_hash_element_line_break.rb