Skip to content

Commit

Permalink
fix(js_formatter): fix comment with single instruction within a contr…
Browse files Browse the repository at this point in the history
…ol flow body (#1655)
  • Loading branch information
mdm317 authored Jan 25, 2024
1 parent 1616d55 commit 6a768ed
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 228 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

- Fix [#1508](https://github.com/biomejs/biome/issues/1508) by excluding deleted files from being processed. Contributed by @ematipico

- Fix [#1173](https://github.com/biomejs/biome/issues/1173). Fix the formatting of a single instruction with commented in a control flow body to ensure consistency. Contributed by @mdm317

### Configuration

### Editors
Expand Down
8 changes: 6 additions & 2 deletions crates/biome_js_formatter/src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,12 @@ fn handle_continue_break_comment(

let enclosing = comment.enclosing_node();

if let Some(preceding) = comment.preceding_node() {
if preceding.kind() == JsSyntaxKind::JS_LABEL {
if let (Some(preceding), Some(parent)) =
(comment.preceding_node(), comment.enclosing_node().parent())
{
if preceding.kind() == JsSyntaxKind::JS_LABEL
&& parent.kind() != JsSyntaxKind::JS_FOR_STATEMENT
{
return CommentPlacement::trailing(preceding.clone(), comment);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ for (const f in {}) break
label1: for (;;) continue label1 /* comment */
;

// FIXME: TODO: reformat issue
// label1: for (;;) continue label1
// /* comment */
// ;
label1: for (;;) continue label1
/* comment */
;

// label1: for (;;) continue label1 // comment
// ;
label1: for (;;) continue label1 // comment
;

// label1: for (;;) continue label1
// // comment
// ;
label1: for (;;) continue label1
// comment
;
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ for (const f in {}) continue;
for (const f in {}) break;
/* comment */

label1: for (;;) continue label1 /* comment */;
label1: for (;;) continue label1; /* comment */

label1: for (;;) continue label1;
/* comment */
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions website/src/content/docs/internals/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

- Fix [#1508](https://github.com/biomejs/biome/issues/1508) by excluding deleted files from being processed. Contributed by @ematipico

- Fix [#1173](https://github.com/biomejs/biome/issues/1173). Fix the formatting of a single instruction with commented in a control flow body to ensure consistency. Contributed by @mdm317

### Configuration

### Editors
Expand Down

0 comments on commit 6a768ed

Please sign in to comment.