Skip to content

Commit

Permalink
fix(js_formatter): fix #1511 (#1547)
Browse files Browse the repository at this point in the history
Co-authored-by: Emanuele Stoppa <[email protected]>
  • Loading branch information
Conaclos and ematipico authored Jan 12, 2024
1 parent a6caba8 commit cf3434c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

- 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

- Fix [#1511](https://github.com/biomejs/biome/issues/1511) that made the JavaScript formatter crash. Contributed @Conaclos

### JavaScript APIs

### Linter
Expand Down Expand Up @@ -1916,7 +1918,7 @@ The following rules are now recommended:
The code action now removes any whitespace between the parameter name and its initialization.
- Relax [noConfusingArrow](https://biomejs.dev/linter/rules/no-confusing-arrow/)
- Relax `noConfusingArrow`
All arrow functions that enclose its parameter with parenthesis are allowed.
Thus, the following snippet no longer trigger the rule:
Expand Down
4 changes: 0 additions & 4 deletions crates/biome_formatter/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,6 @@ fn clean_interned(
Some((mut cleaned, rest)) => {
let mut is_in_expanded_conditional_content = false;
for element in rest {
if is_in_expanded_conditional_content {
continue;
}

let element = match element {
FormatElement::Tag(Tag::StartConditionalContent(condition))
if condition.mode == PrintMode::Expanded =>
Expand Down
3 changes: 3 additions & 0 deletions crates/biome_js_formatter/tests/specs/ts/issue1511.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
call(a, function (b: () => t1 | t2) {});

call(a, (b: () => t1 | t2) => {});
43 changes: 43 additions & 0 deletions crates/biome_js_formatter/tests/specs/ts/issue1511.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
source: crates/biome_formatter_test/src/snapshot_builder.rs
info: ts/issue1511.ts
---

# Input

```ts
call(a, function (b: () => t1 | t2) {});

call(a, (b: () => t1 | t2) => {});

```


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

# 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
-----

```ts
call(a, function (b: () => t1 | t2) {});

call(a, (b: () => t1 | t2) => {});
```


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

- 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

- Fix [#1511](https://github.com/biomejs/biome/issues/1511) that made the JavaScript formatter crash. Contributed @Conaclos

### JavaScript APIs

### Linter
Expand Down Expand Up @@ -1922,7 +1924,7 @@ The following rules are now recommended:

The code action now removes any whitespace between the parameter name and its initialization.

- Relax [noConfusingArrow](https://biomejs.dev/linter/rules/no-confusing-arrow/)
- Relax `noConfusingArrow`

All arrow functions that enclose its parameter with parenthesis are allowed.
Thus, the following snippet no longer trigger the rule:
Expand Down
4 changes: 2 additions & 2 deletions website/src/content/docs/zh-cn/internals/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ The following rules are promoted:

#### Removed rules

- Remove [noConfusingArrow](https://biomejs.dev/linter/rules/no-confusing-arrow/).
- Remove `noConfusingArrow`

Code formatters, such as prettier and Biome, always adds parentheses around the parameter or the body of an arrow function.
This makes the rule useless.
Expand Down Expand Up @@ -1876,7 +1876,7 @@ The following rules are now recommended:

The code action now removes any whitespace between the parameter name and its initialization.

- Relax [noConfusingArrow](https://biomejs.dev/linter/rules/no-confusing-arrow/)
- Relax `noConfusingArrow`

All arrow functions that enclose its parameter with parenthesis are allowed.
Thus, the following snippet no longer trigger the rule:
Expand Down

0 comments on commit cf3434c

Please sign in to comment.