Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/pretty-hornets-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#9505](https://github.com/biomejs/biome/issues/9505): [`noUselessStringConcat`](https://biomejs.dev/linter/rules/no-useless-string-concat/) no longer reports tagged template literals as useless string concatenations. Tagged templates invoke a function and can return non-string values, so combining them with `+` is not equivalent to a single template literal.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ fn is_string_expression(expression: &Option<AnyJsExpression>) -> bool {
(Some(literal_expression), _) => literal_expression
.as_js_string_literal_expression()
.is_some(),
(_, Some(_template_expression)) => true,
(_, Some(template_expression)) => template_expression.tag().is_none(),
_ => false,
}
})
Expand Down Expand Up @@ -373,6 +373,12 @@ fn extract_string_value(expression: &Option<AnyJsExpression>) -> Option<String>
}

Some(AnyJsExpression::JsTemplateExpression(template_expression)) => {
// Tagged templates (e.g. sql`query`) have different semantics and
// their string value cannot be extracted.
if template_expression.tag().is_some() {
return None;
}

let is_useless_template_literal = template_expression
.elements()
.into_iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ const stylisticConcatLeading = 'foo' // formatting
const stylisticConcatLeading = `foo`
+ 'bar'
+ `baz`
// Tagged templates should not be treated as plain strings
const a = t`translate-me` + "!"
const a = "prefix" + sql`query`
const a = tag`a` + tag`b`
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 149
expression: valid.js
---
# Input
Expand All @@ -24,5 +25,9 @@ const stylisticConcatLeading = 'foo' // formatting
const stylisticConcatLeading = `foo`
+ 'bar'
+ `baz`
// Tagged templates should not be treated as plain strings
const a = t`translate-me` + "!"
const a = "prefix" + sql`query`
const a = tag`a` + tag`b`

```