Skip to content

Commit c48d03e

Browse files
committed
fix(formatter): ignore the leading line break for the first argument of the call expression
1 parent 00d6498 commit c48d03e

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

crates/oxc_formatter/src/write/call_arguments.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ impl<'a> Format<'a> for AstNode<'a, ArenaVec<'a, Argument<'a>>> {
9696
);
9797
}
9898

99-
let has_empty_line =
100-
self.iter().any(|arg| f.source_text().get_lines_before(arg.span(), f.comments()) > 1);
99+
let has_empty_line = self
100+
.iter()
101+
.skip(1)
102+
.any(|arg| f.source_text().get_lines_before(arg.span(), f.comments()) > 1);
101103
if has_empty_line
102104
|| (!matches!(self.parent.parent(), AstNodes::Decorator(_))
103105
&& is_function_composition_args(self))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
gen
2+
3+
("a");
4+
5+
gen
6+
7+
(
8+
9+
"b");
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
gen
6+
7+
("a");
8+
9+
gen
10+
11+
(
12+
13+
"b");
14+
==================== Output ====================
15+
gen("a");
16+
17+
gen("b");
18+
19+
===================== End =====================

tasks/coverage/snapshots/formatter_babel.snap

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ commit: 41d96516
22

33
formatter_babel Summary:
44
AST Parsed : 2423/2423 (100.00%)
5-
Positive Passed: 2420/2423 (99.88%)
5+
Positive Passed: 2421/2423 (99.92%)
66
Mismatch: tasks/coverage/babel/packages/babel-parser/test/fixtures/comments/basic/try-statement/input.js
77

8-
Mismatch: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2015/class/division/input.js
9-
108
Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/top-level-await-unambiguous/module/input.js
119
`await` is only allowed within async functions and at the top levels of modules

0 commit comments

Comments
 (0)