class Rufo::Formatter

def visit_literal_elements(elements, inside_hash: false, inside_array: false)

def visit_literal_elements(elements, inside_hash: false, inside_array: false)
  base_column = @column
  needs_final_space = (inside_hash || inside_array) && space?
  skip_space
  if inside_hash
    case @space_after_hash_brace
    when :never
      needs_final_space = false
    when :always
      needs_final_space = true
    end
  end
  if inside_array
    case @space_after_array_bracket
    when :never
      needs_final_space = false
    when :always
      needs_final_space = true
    end
  end
  if newline? || comment?
    needs_final_space = false
  elsif needs_final_space
    consume_space
    base_column = @column
  end
  # If there's a newline right at the beginning,
  # write it, and we'll indent element and always
  # add a trailing comma to the last element
  needs_trailing_comma = newline? || comment?
  if needs_trailing_comma
    if (call_info = @line_to_call_info[@line])
      call_info << true
    end
    needed_indent = next_indent
    indent { consume_end_of_line }
    write_indent(needed_indent)
  else
    needed_indent = base_column
  end
  wrote_comma = false
  last_has_comma = false
  elements.each_with_index do |elem, i|
    is_last = last?(i, elements)
    wrote_comma = false
    last_has_comma = false
    if needs_trailing_comma
      indent(needed_indent) { visit elem }
    else
      visit elem
    end
    # We have to be careful not to aumatically write a heredoc on next_token,
    # because we miss the chance to write a comma to separate elements
    skip_space_no_heredoc_check
    wrote_comma = check_heredocs_in_literal_elements(is_last, needs_trailing_comma, wrote_comma)
    next unless comma?
    last_has_comma = true
    unless is_last
      write ","
      wrote_comma = true
    end
    # We have to be careful not to aumatically write a heredoc on next_token,
    # because we miss the chance to write a comma to separate elements
    next_token_no_heredoc_check
    skip_space_no_heredoc_check
    wrote_comma = check_heredocs_in_literal_elements(is_last, needs_trailing_comma, wrote_comma)
    if newline? || comment?
      if is_last
        # Nothing
      else
        consume_end_of_line
        write_indent(needed_indent)
      end
    else
      write_space unless is_last
    end
  end
  if needs_trailing_comma
    case @trailing_commas
    when :always
      write "," unless wrote_comma
    when :never
      # Nothing
    when :dynamic
      write "," if last_has_comma && !wrote_comma
    end
    consume_end_of_line
    write_indent
  elsif comment?
    consume_end_of_line
  else
    if needs_final_space
      consume_space
    else
      skip_space_or_newline
    end
  end
  call_info << @line if call_info
end