Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js_formatter): correctly format dangling comments of continue statement #2555

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Add parentheses for the return expression that has leading multiline comments. [#2504](https://github.com/biomejs/biome/pull/2504). Contributed by @ah-yu

- Correctly format dangling comments of continue statements. [#2555](https://github.com/biomejs/biome/pull/2555). Contributed by @ah-yu

### JavaScript APIs

### Linter
Expand Down
13 changes: 13 additions & 0 deletions crates/biome_js_formatter/src/js/statements/continue_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,17 @@ impl FormatNodeRule<JsContinueStatement> for FormatJsContinueStatement {

write!(f, [FormatStatementSemicolon::new(semicolon_token.as_ref())])
}

fn fmt_dangling_comments(
&self,
node: &JsContinueStatement,
f: &mut JsFormatter,
) -> FormatResult<()> {
if !f.comments().has_dangling_comments(node.syntax()) {
return Ok(());
}
let content =
format_with(|f| write!(f, [space(), format_dangling_comments(node.syntax())]));
write!(f, [line_suffix(&content), expand_parent()])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for (const f of fs) {
if (condition) continue; //commment
else continue; // comment
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
source: crates/biome_formatter_test/src/snapshot_builder.rs
info: js/module/statement/continue_stmt.js
---
# Input

```js
for (const f of fs) {
if (condition) continue; //commment
else continue; // comment
}
```


=============================

# Outputs

## Output 1

-----
Indent style: Tab
Indent width: 2
Line ending: LF
Line width: 80
Quote style: Double Quotes
JSX quote style: Double Quotes
Quote properties: As needed
Trailing comma: All
Semicolons: Always
Arrow parentheses: Always
Bracket spacing: true
Bracket same line: false
Attribute Position: Auto
-----

```js
for (const f of fs) {
if (condition)
continue; //commment
else continue; // comment
}
```