class RuboCop::Cop::Layout::FirstArrayElementLineBreak

Checks for a line break before the first element in a multi-line array.

@example

# bad
[ :a,
  :b]

# good
[
  :a,
  :b]

# good
[:a, :b]

@example AllowMultilineFinalElement: false (default)

# bad
[ :a, {
  :b => :c
}]

# good
[
  :a, {
  :b => :c
}]

@example AllowMultilineFinalElement: true

# good
[:a, {
  :b => :c
}]

Constants

MSG

Public Instance Methods

on_array(node) click to toggle source
# File lib/rubocop/cop/layout/first_array_element_line_break.rb, line 49
def on_array(node)
  return if !node.loc.begin && !assignment_on_same_line?(node)

  check_children_line_break(node, node.children, ignore_last: ignore_last_element?)
end

Private Instance Methods

assignment_on_same_line?(node) click to toggle source
# File lib/rubocop/cop/layout/first_array_element_line_break.rb, line 57
def assignment_on_same_line?(node)
  source = node.source_range.source_line[0...node.loc.column]
  /\s*=\s*$/.match?(source)
end
ignore_last_element?() click to toggle source
# File lib/rubocop/cop/layout/first_array_element_line_break.rb, line 62
def ignore_last_element?
  !!cop_config['AllowMultilineFinalElement']
end