Skip to content

Commit c6942d2

Browse files
siketyanematipico
andauthored
fix(formatter): don't insert an empty line before semicolon with leading comments (#6388)
Co-authored-by: Emanuele Stoppa <[email protected]>
1 parent 3852691 commit c6942d2

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

.changeset/yellow-hornets-lose.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#6375](https://github.com/biomejs/biome/issues/6375): the formatter no longer inserts an extra empty line before a semicolon when it has leading comments.

crates/biome_js_formatter/src/js/statements/expression_statement.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ impl FormatNodeRule<JsExpressionStatement> for FormatJsExpressionStatement {
3030
.prev_sibling()
3131
.and_then(|sibling| sibling.last_token())
3232
{
33-
if token.kind() == T![;] && get_lines_before_token(&token) > 1 {
33+
if token.kind() == T![;]
34+
&& !token.has_leading_comments()
35+
&& get_lines_before_token(&token) > 1
36+
{
3437
write!(f, [empty_line()])?;
3538
}
3639
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const Transport = {}
2+
const newRequest = {}
3+
4+
/**
5+
* SAFETY: monkey patching and getting around the provided type definitions.
6+
*/
7+
;(Transport.prototype as any).request = newRequest
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
source: crates/biome_formatter_test/src/snapshot_builder.rs
3+
info: js/module/no-semi/issue6375.js
4+
---
5+
# Input
6+
7+
```js
8+
const Transport = {}
9+
const newRequest = {}
10+
11+
/**
12+
* SAFETY: monkey patching and getting around the provided type definitions.
13+
*/
14+
;(Transport.prototype as any).request = newRequest
15+
16+
```
17+
18+
19+
=============================
20+
21+
# Outputs
22+
23+
## Output 1
24+
25+
-----
26+
Indent style: Tab
27+
Indent width: 2
28+
Line ending: LF
29+
Line width: 80
30+
Quote style: Double Quotes
31+
JSX quote style: Double Quotes
32+
Quote properties: As needed
33+
Trailing commas: All
34+
Semicolons: Always
35+
Arrow parentheses: Always
36+
Bracket spacing: true
37+
Bracket same line: false
38+
Attribute Position: Auto
39+
Expand lists: Auto
40+
-----
41+
42+
```js
43+
const Transport = {};
44+
const newRequest = {};
45+
46+
/**
47+
* SAFETY: monkey patching and getting around the provided type definitions.
48+
*/
49+
(Transport.prototype as any).request = newRequest;
50+
```
51+
52+
## Output 1
53+
54+
-----
55+
Indent style: Tab
56+
Indent width: 2
57+
Line ending: LF
58+
Line width: 80
59+
Quote style: Double Quotes
60+
JSX quote style: Double Quotes
61+
Quote properties: As needed
62+
Trailing commas: All
63+
Semicolons: As needed
64+
Arrow parentheses: Always
65+
Bracket spacing: true
66+
Bracket same line: false
67+
Attribute Position: Auto
68+
Expand lists: Auto
69+
-----
70+
71+
```js
72+
const Transport = {}
73+
const newRequest = {}
74+
75+
/**
76+
* SAFETY: monkey patching and getting around the provided type definitions.
77+
*/
78+
;(Transport.prototype as any).request = newRequest
79+
```

0 commit comments

Comments
 (0)