useTemplate
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
¥Diagnostic Category:
lint/style/useTemplate -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
与
prefer-template相同¥Same as
prefer-template
-
¥How to configure
{ "linter": { "rules": { "style": { "useTemplate": "error" } } }}¥Description
首选模板文字而不是字符串连接。
¥Prefer template literals over string concatenation.
¥Examples
¥Invalid
const s = foo + "baz";code-block.js:1:11 lint/style/useTemplate FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Template literals are preferred over string concatenation.
> 1 │ const s = foo + “baz”;
│ ^^^^^^^^^^^
2 │
ℹ Unsafe fix: Use a template literal.
1 │ - const·s·=·foo·+·“baz”;
1 │ + const·s·=·`${foo}baz`;
2 2 │
const s = 1 + 2 + "foo" + 3;code-block.js:1:11 lint/style/useTemplate FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Template literals are preferred over string concatenation.
> 1 │ const s = 1 + 2 + “foo” + 3;
│ ^^^^^^^^^^^^^^^^^
2 │
ℹ Unsafe fix: Use a template literal.
1 │ - const·s·=·1·+·2·+·“foo”·+·3;
1 │ + const·s·=·`${1·+·2}foo${3}`;
2 2 │
const s = 1 * 2 + "foo";code-block.js:1:11 lint/style/useTemplate FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Template literals are preferred over string concatenation.
> 1 │ const s = 1 * 2 + “foo”;
│ ^^^^^^^^^^^^^
2 │
ℹ Unsafe fix: Use a template literal.
1 │ - const·s·=·1·*·2·+·“foo”;
1 │ + const·s·=·`${1·*·2}foo`;
2 2 │
const s = 1 + "foo" + 2 + "bar" + "baz" + 3;code-block.js:1:11 lint/style/useTemplate FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Template literals are preferred over string concatenation.
> 1 │ const s = 1 + “foo” + 2 + “bar” + “baz” + 3;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Unsafe fix: Use a template literal.
1 │ - const·s·=·1·+·“foo”·+·2·+·“bar”·+·“baz”·+·3;
1 │ + const·s·=·`${1}foo${2}barbaz${3}`;
2 2 │
¥Valid
let s = "foo" + "bar" + `baz`;let s = `value: ${1}`;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号