From 92ad11ce70bee2135b22d63ae92ffa892d5c7984 Mon Sep 17 00:00:00 2001 From: Victorien Elvinger Date: Fri, 12 Jan 2024 21:42:34 +0100 Subject: [PATCH] fix(js_formatter): fix #1511 --- CHANGELOG.md | 4 +- crates/biome_formatter/src/buffer.rs | 4 -- .../tests/specs/ts/issue1511.ts | 3 ++ .../tests/specs/ts/issue1511.ts.snap | 43 +++++++++++++++++++ .../src/content/docs/internals/changelog.mdx | 4 +- .../docs/zh-cn/internals/changelog.mdx | 4 +- 6 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 crates/biome_js_formatter/tests/specs/ts/issue1511.ts create mode 100644 crates/biome_js_formatter/tests/specs/ts/issue1511.ts.snap diff --git a/CHANGELOG.md b/CHANGELOG.md index 348d64aca7ae..868a76563829 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,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 @@ -1911,7 +1913,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: diff --git a/crates/biome_formatter/src/buffer.rs b/crates/biome_formatter/src/buffer.rs index 420990336ca7..5012067d2c96 100644 --- a/crates/biome_formatter/src/buffer.rs +++ b/crates/biome_formatter/src/buffer.rs @@ -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 => diff --git a/crates/biome_js_formatter/tests/specs/ts/issue1511.ts b/crates/biome_js_formatter/tests/specs/ts/issue1511.ts new file mode 100644 index 000000000000..5ea570eb2e82 --- /dev/null +++ b/crates/biome_js_formatter/tests/specs/ts/issue1511.ts @@ -0,0 +1,3 @@ +call(a, function (b: () => t1 | t2) {}); + +call(a, (b: () => t1 | t2) => {}); diff --git a/crates/biome_js_formatter/tests/specs/ts/issue1511.ts.snap b/crates/biome_js_formatter/tests/specs/ts/issue1511.ts.snap new file mode 100644 index 000000000000..c39f8cb433b1 --- /dev/null +++ b/crates/biome_js_formatter/tests/specs/ts/issue1511.ts.snap @@ -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) => {}); +``` + + diff --git a/website/src/content/docs/internals/changelog.mdx b/website/src/content/docs/internals/changelog.mdx index 729bddb5ee72..4e9bebb6bc7f 100644 --- a/website/src/content/docs/internals/changelog.mdx +++ b/website/src/content/docs/internals/changelog.mdx @@ -38,6 +38,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 @@ -1917,7 +1919,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: diff --git a/website/src/content/docs/zh-cn/internals/changelog.mdx b/website/src/content/docs/zh-cn/internals/changelog.mdx index 0eb0fdcdc773..36ce590a7b15 100644 --- a/website/src/content/docs/zh-cn/internals/changelog.mdx +++ b/website/src/content/docs/zh-cn/internals/changelog.mdx @@ -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. @@ -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: