Skip to content

Commit

Permalink
fix(js_formatter): correctly format dangling comments of continue sta…
Browse files Browse the repository at this point in the history
…tement (#2555)
  • Loading branch information
ah-yu committed Apr 22, 2024
1 parent afbd2a6 commit f3afb52
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
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
}
```

0 comments on commit f3afb52

Please sign in to comment.