Skip to content

Commit 48e65dd

Browse files
committed
fix(formatter): should not add a trailing comma for long curried calls when trailingComma is es5
1 parent 3e29d23 commit 48e65dd

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

crates/oxc_formatter/src/write/call_arguments.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,14 @@ impl<'a> Format<'a> for AstNode<'a, ArenaVec<'a, Argument<'a>>> {
124124
if let Some(group_layout) = arguments_grouped_layout(call_like_span, self, f) {
125125
write_grouped_arguments(self, group_layout, f)
126126
} else if call_expression.is_some_and(|call| is_long_curried_call(call)) {
127+
let trailing_operator = FormatTrailingCommas::All.trailing_separator(f.options());
127128
write!(
128129
f,
129130
[
130131
l_paren_token,
131132
soft_block_indent(&format_once(|f| {
132133
f.join_with(soft_line_break_or_space())
133-
.entries_with_trailing_separator(
134-
self.iter(),
135-
",",
136-
TrailingSeparator::Allowed,
137-
)
134+
.entries_with_trailing_separator(self.iter(), ",", trailing_operator)
138135
.finish()
139136
})),
140137
r_paren_token,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{
3+
"trailingComma": "none"
4+
},
5+
{
6+
"trailingComma": "es5"
7+
},
8+
{
9+
"trailingComma": "all"
10+
}
11+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Event.debounce(
2+
call(A, B),
3+
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
4+
)(() => { });
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
Event.debounce(
6+
call(A, B),
7+
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
8+
)(() => { });
9+
10+
==================== Output ====================
11+
-------------------------
12+
{ trailingComma: "none" }
13+
-------------------------
14+
Event.debounce(
15+
call(A, B),
16+
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
17+
)(() => {});
18+
19+
------------------------
20+
{ trailingComma: "es5" }
21+
------------------------
22+
Event.debounce(
23+
call(A, B),
24+
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
25+
)(() => {});
26+
27+
------------------------
28+
{ trailingComma: "all" }
29+
------------------------
30+
Event.debounce(
31+
call(A, B),
32+
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD,
33+
)(() => {});
34+
35+
===================== End =====================

0 commit comments

Comments
 (0)