You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixed [#7230](https://github.com/biomejs/biome/issues/7230): [`noUselessStringConcat`](https://biomejs.dev/linter/rules/no-useless-string-concat/) no longer emits false positives for multi-line strings with leading `+` operators.
6
+
7
+
Previously, the rule did not check for leading newlines on the `+` operator, emitting false positives if one occurred at the start of a line. \
8
+
Notably, formatting with `operatorLinebreak="before"` would move the `+` operators to the start of lines automatically, resulting in spurious errors whenever a multi-line string was used.
9
+
10
+
Now, the rule correctly detects and ignores multi-line concatenations with leading operators as well, working regardless of the setting of `operatorLinebreak`.
11
+
12
+
**Example**
13
+
```ts
14
+
// The following code used to error if the `+` operators were at the start of lines (as opposed to the end).
15
+
// Now, the rule correctly recognizes this as a stylistic concatenation and ignores it.
16
+
const reallyLongStringThatShouldNotError =
17
+
"Lorem ipsum dolor sit amet consectetur adipiscing elit."
18
+
+"Quisque faucibus ex sapien vitae pellentesque sem placerat."
19
+
+"In id cursus mi pretium tellus duis convallis."
20
+
+"Tempus leo eu aenean sed diam urna tempor. Pulvinar vivamus fringilla";
Copy file name to clipboardExpand all lines: crates/biome_js_analyze/src/lint/complexity/no_useless_string_concat.rs
+90-67Lines changed: 90 additions & 67 deletions
Original file line number
Diff line number
Diff line change
@@ -17,8 +17,10 @@ use crate::JsRuleAction;
17
17
declare_lint_rule!{
18
18
/// Disallow unnecessary concatenation of string or template literals.
19
19
///
20
-
/// This rule aims to flag the concatenation of 2 literals when they could be combined into a single literal. Literals can be strings or template literals.
21
-
/// Concatenation of multiple strings is allowed when the strings are spread over multiple lines in order to prevent exceeding the maximum line width.
20
+
/// This rule aims to flag concatenation of string or template literals when they could be combined into a single literal.
21
+
/// Notably, this also includes concatenating a string with a number (unlike the derivative ESLint rule).
22
+
///
23
+
/// Concatenation of multiple strings is allowed for multi-line strings (such as ones used to prevent exceeding the maximum line width).
22
24
///
23
25
/// ## Examples
24
26
///
@@ -29,6 +31,10 @@ declare_lint_rule! {
29
31
/// ```
30
32
///
31
33
/// ```js,expect_diagnostic
34
+
/// const foo = "string" + 123;
35
+
/// ```
36
+
///
37
+
/// ```js,expect_diagnostic
32
38
/// const a = "a" + "b" + "c";
33
39
/// ```
34
40
///
@@ -58,10 +64,18 @@ declare_lint_rule! {
58
64
/// const a = 'foo' + bar;
59
65
/// ```
60
66
///
67
+
/// Multi-line strings are ignored:
68
+
///
61
69
/// ```js
62
-
/// const a = 'foo' +
70
+
/// const multiline = 'foo' + // formatting
63
71
/// 'bar'
64
72
/// ```
73
+
///
74
+
/// ```js
75
+
/// const alsoMultiline = 'foo'
76
+
/// + 'bar'
77
+
/// + `baz`
78
+
/// ```
65
79
pubNoUselessStringConcat{
66
80
version:"1.8.0",
67
81
name:"noUselessStringConcat",
@@ -84,13 +98,13 @@ impl Rule for NoUselessStringConcat {
84
98
let parent_binary_expression = get_parent_binary_expression(node);
85
99
86
100
// Prevent duplicated error reportings when the parent is a useless concatenation too, i.e.: "a" + "b" + "c"
0 commit comments