class Rufo::Formatter
def visit_command_args(args, base_column)
def visit_command_args(args, base_column) needed_indent = @column args_is_def_class_or_module = false param_column = current_token_column # Check if there's a single argument and it's # a def, class or module. In that case we don't # want to align the content to the position of # that keyword. if args[0] == :args_add_block nested_args = args[1] if nested_args.is_a?(Array) && nested_args.size == 1 first = nested_args[0] if first.is_a?(Array) case first[0] when :def, :class, :module needed_indent = @indent args_is_def_class_or_module = true end end end end base_line = @line call_info = @line_to_call_info[@line] if call_info call_info = nil else call_info = [@indent, @column] @line_to_call_info[@line] = call_info end old_want_first_token_in_line = @want_first_token_in_line @want_first_token_in_line = true # We align call parameters to the first paramter indent(needed_indent) do visit_exps to_ary(args), with_lines: false end if call_info && call_info.size > 2 # A call like: # # foo, 1, [ # 2, # ] # # would normally be aligned like this (with the first parameter): # # foo, 1, [ # 2, # ] # # However, the first style is valid too and we preserve it if it's # already formatted like that. call_info << @line elsif !args_is_def_class_or_module && @first_token_in_line && param_column == @first_token_in_line[0][1] # If the last line of the call is aligned with the first parameter, leave it like that: # # foo 1, # 2 elsif !args_is_def_class_or_module && @first_token_in_line && base_column + INDENT_SIZE == @first_token_in_line[0][1] # Otherwise, align it just by two spaces (so we need to dedent, we fake a dedent here) # # foo 1, # 2 @line_to_call_info[base_line] = [0, needed_indent - next_indent, true, @line, @line] end @want_first_token_in_line = old_want_first_token_in_line end