Перейти до вмісту

noTemplateCurlyInString

Цей контент ще не доступний вашою мовою.

Diagnostic Category: lint/nursery/noTemplateCurlyInString

Since: v1.9.3

Sources:

Disallow template literal placeholder syntax in regular strings.

ECMAScript 6 allows programmers to create strings containing variable or expressions using template literals, instead of string concatenation, by writing expressions like ${variable} between two backtick quotes (`). It can be easy to use the wrong quotes when wanting to use template literals, by writing "${variable}", and end up with the literal value "${variable}" instead of a string containing the value of the injected expressions.

const a = "Hello ${name}!";
code-block.js:1:18 lint/nursery/noTemplateCurlyInString ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected template string placeholder.

> 1 │ const a = “Hello ${name}!”;
^^^^^^^
2 │

Turn the string into a template string.

const a = 'Hello ${name}!';
code-block.js:1:18 lint/nursery/noTemplateCurlyInString ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected template string placeholder.

> 1 │ const a = ‘Hello ${name}!’;
^^^^^^^
2 │

Turn the string into a template string.

const a = "Time: ${12 * 60 * 60 * 1000}";
code-block.js:1:18 lint/nursery/noTemplateCurlyInString ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected template string placeholder.

> 1 │ const a = “Time: ${12 * 60 * 60 * 1000}”;
^^^^^^^^^^^^^^^^^^^^^^
2 │

Turn the string into a template string.

const a = `Hello ${name}!`;
const a = `Time: ${12 * 60 * 60 * 1000}`;
const a = templateFunction`Hello ${name}`;
biome.json
{
"linter": {
"rules": {
"nursery": {
"noTemplateCurlyInString": "error"
}
}
}
}