class Rufo::Formatter
def visit_literal_elements(elements, inside_hash: false)
def visit_literal_elements(elements, inside_hash: false) base_column = @column needs_final_space = inside_hash && space? skip_space case @space_after_hash_brace when :never needs_final_space = false when :always needs_final_space = true 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 needed_indent = next_indent indent { consume_end_of_line } write_indent(needed_indent) else needed_indent = base_column end wrote_comma = false elements.each_with_index do |elem, i| is_last = last?(i, elements) wrote_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? 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 write "," unless wrote_comma 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 end