diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index ccccf320..9402fc96 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -1541,7 +1541,8 @@ def visit_args_add_star(node) skip_space - write_params_comma if comma? + # Disable indentation in write_params_comma to avoid double indentation with write_indent + write_params_comma(with_indent: !needs_indent) if comma? write_indent(base_column) if needs_indent consume_op "*" skip_space_or_newline @@ -1551,7 +1552,8 @@ def visit_args_add_star(node) end if post_args && !post_args.empty? - write_params_comma + # Disable indentation in write_params_comma to avoid double indentation with visit_comma_separated_list + write_params_comma(with_indent: !needs_indent) visit_comma_separated_list post_args, needs_indent: needs_indent, base_column: base_column end end @@ -2250,12 +2252,14 @@ def visit_params(node) end end - def write_params_comma + def write_params_comma(with_indent: true) skip_space check :on_comma write "," next_token - skip_space_or_newline_using_setting(:one) + + indent_size = with_indent ? @indent : 0 + skip_space_or_newline_using_setting(:one, indent_size) end def visit_array(node) diff --git a/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec b/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec index 71bed7b1..ff97566c 100644 --- a/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec @@ -736,3 +736,91 @@ foo(*bar, baz, #~# EXPECTED foo(*bar, baz, qux) + +#~# ORIGINAL issue_228 +class Foo + bar( + :foo, + *bar, + :qux, + ) +end + +#~# EXPECTED +class Foo + bar( + :foo, + *bar, + :qux, + ) +end + +#~# ORIGINAL issue_228_2 +class Foo + def foo + bar.bar( + :foo, + *bar, + :qux, + ) + end +end + +#~# EXPECTED +class Foo + def foo + bar.bar( + :foo, + *bar, + :qux, + ) + end +end + +#~# ORIGINAL issue_228_3 +class Foo +def bar +x = foo.bar( + a, + *b, + c, + e: f, +) + end +end + +#~# EXPECTED +class Foo + def bar + x = foo.bar( + a, + *b, + c, + e: f, + ) + end +end + +#~# ORIGINAL issue_228_4 +class Foo +def bar +bar( +*a, + *b, + c, + d, +) + end +end + +#~# EXPECTED +class Foo + def bar + bar( + *a, + *b, + c, + d, + ) + end +end