class Rufo::Formatter
def visit_q_or_i_array(node)
def visit_q_or_i_array(node) _, elements = node # For %W it seems elements appear inside other arrays # for some reason, so we flatten them if elements[0].is_a?(Array) && elements[0][0].is_a?(Array) elements = elements.flat_map { |x| x } end write current_token_value.strip # If there's a newline after `%w(`, write line and indent if current_token_value.include?("\n") && elements write_line write_indent(next_indent) end next_token if elements elements.each_with_index do |elem, i| if elem[0] == :@tstring_content # elem is [:@tstring_content, string, [1, 5] write elem[1].strip next_token else visit elem end if !last?(i, elements) && current_token_kind == :on_words_sep # On a newline, write line and indent if current_token_value.include?("\n") next_token write_line write_indent(next_indent) else next_token write_space " " end end end end has_newline = false last_token = nil while current_token_kind == :on_words_sep has_newline ||= current_token_value.include?("\n") unless current_token[2].strip.empty? last_token = current_token end next_token end if has_newline write_line write_indent(next_indent) end if last_token write last_token[2].strip else write current_token_value.strip next_token end end