Skip to content

Commit

Permalink
Merge pull request #320 from ruby-formatter/fix-228
Browse files Browse the repository at this point in the history
Fix #228
  • Loading branch information
kzkn authored Feb 3, 2024
2 parents 950d2e3 + 5cca39a commit 42e7a97
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/rufo/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
88 changes: 88 additions & 0 deletions spec/lib/rufo/formatter_source_specs/method_calls.rb.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 42e7a97

Please sign in to comment.