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 has_space = current_token_value.end_with?(" ") write current_token_value.strip # (pre 2.5.0) If there's a newline after `%w(`, write line and indent if current_token_value.include?("\n") && elements # "%w[\n" write_line write_indent next_indent end next_token # fix for 2.5.0 ripper change if current_token_kind == :on_words_sep && elements && !elements.empty? value = current_token_value has_space = value.start_with?(" ") if value.include?("\n") && elements # "\n " write_line write_indent next_indent end next_token has_space = true if current_token_value.start_with?(" ") end if elements && !elements.empty? write_space if has_space column = @column 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(column) 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 elsif has_space && elements && !elements.empty? write_space end if last_token write last_token[2].strip else write current_token_value.strip next_token end end