class RuboCop::Cop::Layout::FirstHashElementLineBreak
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 } # good { a: 1, b: { c: 3 }}
@example AllowMultilineFinalElement: false (default)
# bad { a: 1, b: { c: 3 }}
@example AllowMultilineFinalElement: true
# bad { a: 1, b: { c: 3 }} # good { a: 1, b: { c: 3 }}
Constants
- MSG
Public Instance Methods
Source
# File lib/rubocop/cop/layout/first_hash_element_line_break.rb, line 52 def on_hash(node) # node.loc.begin tells us whether the hash opens with a { # If it doesn't, Layout/FirstMethodArgumentLineBreak will handle it return unless node.loc.begin check_children_line_break(node, node.children, ignore_last: ignore_last_element?) end
Private Instance Methods
Source
# File lib/rubocop/cop/layout/first_hash_element_line_break.rb, line 62 def ignore_last_element? !!cop_config['AllowMultilineFinalElement'] end