Skip to content

Commit

Permalink
fix(js_formatter): ensure comments before * are placed before * i…
Browse files Browse the repository at this point in the history
…n generators (#1537)
  • Loading branch information
ah-yu authored Jan 12, 2024
1 parent e8d4335 commit 0a291cb
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

#### Bug fixes

- Fix placement of comments before `*` token in generator methods with decorators. [#1537](https://github.com/biomejs/biome/pull/1537) Contributed by @ah-yu

- Fix [#1406](https://github.com/biomejs/biome/issues/1406). Ensure comments before the `async` keyword are placed before it. Contributed by @ah-yu

- Fix [#1172](https://github.com/biomejs/biome/issues/1172). Fix placement of line comment after function expression parentheses, they are now attached to first statement in body. Contributed by @kalleep
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 @@ -1256,7 +1256,8 @@ fn handle_import_export_specifier_comment(
}
}

/// Ensure that comments before the `async`` keyword are placed just before it.
/// Attach comments before the `async` keyword or `*` token to the preceding node if it exists
/// to ensure these comments are placed before the `async` keyword or `*` token.
/// ```javascript
/// class Foo {
/// @decorator()
Expand All @@ -1270,7 +1271,10 @@ fn handle_class_method_comment(
match enclosing_node.kind() {
JsSyntaxKind::JS_METHOD_CLASS_MEMBER => {
if let Some(following_token) = comment.following_token() {
if following_token.kind() == JsSyntaxKind::ASYNC_KW {
if matches!(
following_token.kind(),
JsSyntaxKind::ASYNC_KW | JsSyntaxKind::STAR
) {
if let Some(preceding) = comment.preceding_node() {
return CommentPlacement::trailing(preceding.clone(), comment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ class Foo {
/*after*/
async method() {}
@decorator.method(value) /*before*/
*/*after*/ method() {}
/*after*/
*method() {}
@decorator.method(value) /*before*/
get /*after*/ getter() {}
@decorator.method(value) /*before*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ class Foo {
/*after*/
async method() {}
@decorator /*before*/
*/*after*/ method() {}
/*after*/
*method() {}
@decorator.method(value) /*before*/
get /*after*/ getter() {}
@decorator /*before*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ class Foo {
/*after*/
async method() {}
@dec /*before*/
*/*after*/ method() {}
/*after*/
*method() {}
@dec /*before*/
get /*after*/ getter() {}
@dec /*before*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@ class Something2 {
```diff
--- Prettier
+++ Biome
@@ -12,8 +12,8 @@

class Foo3 {
@foo
- // comment
- *method() {}
+ *// comment
+ method() {}
}

class Foo4 {
@@ -30,6 +30,6 @@

class Something2 {
Expand Down Expand Up @@ -90,8 +79,8 @@ class Foo2 {

class Foo3 {
@foo
*// comment
method() {}
// comment
*method() {}
}

class Foo4 {
Expand Down
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 @@ -32,6 +32,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

#### Bug fixes

- Fix placement of comments before `*` token in generator methods with decorators. [#1537](https://github.com/biomejs/biome/pull/1537) Contributed by @ah-yu

- Fix [#1406](https://github.com/biomejs/biome/issues/1406). Ensure comments before the `async` keyword are placed before it. Contributed by @ah-yu

- Fix [#1172](https://github.com/biomejs/biome/issues/1172). Fix placement of line comment after function expression parentheses, they are now attached to first statement in body. Contributed by @kalleep
Expand Down

0 comments on commit 0a291cb

Please sign in to comment.