Skip to content

Commit

Permalink
fix(js_formatter): add parentheses for the return expression that has…
Browse files Browse the repository at this point in the history
… leading multiline comments. (#2504)
  • Loading branch information
ah-yu authored Apr 18, 2024
1 parent dbab2b9 commit 3d0b473
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 51 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

#### Bug fixes

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

### JavaScript APIs

### Linter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ fn has_argument_leading_comments(argument: &AnyJsExpression, comments: &JsCommen
return true;
}

if comments
.leading_comments(argument.syntax())
.iter()
.any(|comment| comment.piece().has_newline())
{
return true;
};

current = get_expression_left_side(&expression);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,23 @@ function f1() {

function f2() {
return 1,3,4
}

function f3() {
return /* commment */'1'
}

function f4() {
return (
/* comment */
'1'
)
}

function f5() {
return (
/*
* multiline comment
*/ '1'
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
source: crates/biome_formatter_test/src/snapshot_builder.rs
info: js/module/statement/return.js
---

# Input

```js
Expand All @@ -13,6 +12,25 @@ function f1() {
function f2() {
return 1,3,4
}

function f3() {
return /* commment */'1'
}

function f4() {
return (
/* comment */
'1'
)
}

function f5() {
return (
/*
* multiline comment
*/ '1'
)
}
```


Expand Down Expand Up @@ -46,6 +64,23 @@ function f1() {
function f2() {
return 1, 3, 4;
}
```

function f3() {
return /* commment */ "1";
}

function f4() {
return (
/* comment */
"1"
);
}

function f5() {
return (
/*
* multiline comment
*/ "1"
);
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ function inlineComment() {
) || 42
}

// TODO: fix idempotency issue
// function multilineBlockSameLine() {
// return (
// /**
// * @type {string}
// */ 'result'
// )
// }

function multilineBlockSameLine() {
return (
/**
* @type {string}
*/ 'result'
)
}

function multilineBlockNextLine() {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
source: crates/biome_formatter_test/src/snapshot_builder.rs
info: js/comments/return-statement.js
---

# Input

```js
Expand Down Expand Up @@ -128,14 +127,14 @@ function inlineComment() {
) || 42
}

// TODO: fix idempotency issue
// function multilineBlockSameLine() {
// return (
// /**
// * @type {string}
// */ 'result'
// )
// }

function multilineBlockSameLine() {
return (
/**
* @type {string}
*/ 'result'
)
}

function multilineBlockNextLine() {
return (
Expand Down Expand Up @@ -201,28 +200,6 @@ function singleLineBlockNextLine() {
}

function excessiveEverything() {
@@ -119,13 +121,14 @@
return /* hi */ 42 || 42;
}

-function multilineBlockSameLine() {
- return (
- /**
- * @type {string}
- */ "result"
- );
-}
+// TODO: fix idempotency issue
+// function multilineBlockSameLine() {
+// return (
+// /**
+// * @type {string}
+// */ 'result'
+// )
+// }

function multilineBlockNextLine() {
return (
```

# Output
Expand Down Expand Up @@ -351,14 +328,13 @@ function inlineComment() {
return /* hi */ 42 || 42;
}

// TODO: fix idempotency issue
// function multilineBlockSameLine() {
// return (
// /**
// * @type {string}
// */ 'result'
// )
// }
function multilineBlockSameLine() {
return (
/**
* @type {string}
*/ "result"
);
}

function multilineBlockNextLine() {
return (
Expand Down Expand Up @@ -397,5 +373,3 @@ function singleLineBlockNextLine() {
);
}
```


2 changes: 2 additions & 0 deletions website/src/content/docs/internals/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

#### Bug fixes

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

### JavaScript APIs

### Linter
Expand Down

0 comments on commit 3d0b473

Please sign in to comment.