Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js_format): fix js template element parentheses issue #3780

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/biome_js_formatter/src/syntax_rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ impl JsFormatSyntaxRewriter {
let prev_token = l_paren.prev_token();
// Keep parentheses around unknown expressions. Biome can't know the precedence.
if inner.kind().is_bogus()
// Don't remove parentheses if the expression in js template element
|| inner.grand_parent().is_some_and(|parent|
parent.grand_parent().is_some_and(|node|
node.kind() == JsSyntaxKind::JS_TEMPLATE_ELEMENT
)
)
// Don't remove parentheses if the expression is a decorator
|| inner.grand_parent().is_some_and(|node| node.kind() == JsSyntaxKind::JS_DECORATOR && decorator_expression_needs_parens(&inner))
// Don't remove parentheses if they have skipped trivia. We don't know for certain what the intended syntax is.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@ which already had a linebreak so can be broken up
message = `this is a long messsage a simple interpolation without a linebreak \${foo} <- like this\`;
message = \`whereas this messsage has a linebreak in the interpolation \${
foo
} <- like this`;
} <- like this`;

// https://github.com/biomejs/biome/issues/3766
const issus_3766 = `Lectures: ${doneCount}/${totalCount} | Mins: ${(doneSecs / 60).toFixed(
2,
)}/${(totalSecs / 60).toFixed(
2,
)}| Hours: ${(doneSecs / 3600).toFixed(
2,
)}/${(totalSecs / 3600).toFixed(
2,
)}`;
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ message = `this is a long messsage a simple interpolation without a linebreak \$
message = \`whereas this messsage has a linebreak in the interpolation \${
foo
} <- like this`;

// https://github.com/biomejs/biome/issues/3766
const issus_3766 = `Lectures: ${doneCount}/${totalCount} | Mins: ${(doneSecs / 60).toFixed(
2,
)}/${(totalSecs / 60).toFixed(
2,
)}| Hours: ${(doneSecs / 3600).toFixed(
2,
)}/${(totalSecs / 3600).toFixed(
2,
)}`;
```


Expand Down Expand Up @@ -169,6 +180,13 @@ message = `this is a long messsage a simple interpolation without a linebreak \$
message = \`whereas this messsage has a linebreak in the interpolation \${
foo
} <- like this`;

// https://github.com/biomejs/biome/issues/3766
const issus_3766 = `Lectures: ${doneCount}/${totalCount} | Mins: ${(
doneSecs / 60
).toFixed(2)}/${(totalSecs / 60).toFixed(2)}| Hours: ${(
doneSecs / 3600
).toFixed(2)}/${(totalSecs / 3600).toFixed(2)}`;
```

# Lines exceeding max width of 80 characters
Expand Down
Loading