noTemplateCurlyInString
¥Summary
-
规则生效日期:
v1.9.3¥Rule available since:
v1.9.3 -
诊断类别:
lint/suspicious/noTemplateCurlyInString¥Diagnostic Category:
lint/suspicious/noTemplateCurlyInString -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
-
与
no-template-curly-in-string相同¥Same as
no-template-curly-in-string
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noTemplateCurlyInString": "error" } } }}¥Description
禁止在普通字符串中使用模板字面量占位符语法。
¥Disallow template literal placeholder syntax in regular strings.
ECMAScript 6 允许程序员使用模板字面量(而非字符串连接)创建包含变量或表达式的字符串,方法是将表达式(例如 ${variable})写在两个反引号 (`) 之间。在使用模板字面量时,很容易因为使用了错误的引号而导致代码出现错误。例如,如果写成 "${variable}",最终得到的是字面值 "${variable}",而不是包含注入表达式值的字符串。
¥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.
¥Examples
¥Invalid
const a = "Hello ${name}!";code-block.js:1:18 lint/suspicious/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/suspicious/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/suspicious/noTemplateCurlyInString ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Unexpected template string placeholder.
> 1 │ const a = “Time: ${12 * 60 * 60 * 1000}”;
│ ^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Turn the string into a template string.
¥Valid
const a = `Hello ${name}!`;const a = `Time: ${12 * 60 * 60 * 1000}`;
const a = templateFunction`Hello ${name}`;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号