noUnnecessaryTemplateExpression
Esta página aún no está disponible en tu idioma.
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/noUnnecessaryTemplateExpression - This rule has a safe fix.
- The default severity of this rule is information.
- Sources:
- Inspired from
@typescript-eslint/no-unnecessary-template-expression
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noUnnecessaryTemplateExpression": "error" } } }}Description
Section titled “Description”Disallow unnecessary template expressions.
A template expression (or template literal) is unnecessary when it only contains string literal expressions that could be written as a regular string literal instead.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”const a = `${'hello'}`;code-block.js:1:11 lint/nursery/noUnnecessaryTemplateExpression FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This template expression is unnecessary.
> 1 │ const a = `${‘hello’}`;
│ ^^^^^^^^^^^^
2 │
ℹ The template only contains string literal expressions. A regular string literal can be used instead.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Safe fix: Replace the template expression with a string literal.
1 │ - const·a·=·`${‘hello’}`;
1 │ + const·a·=·“hello”;
2 2 │
const b = `${"world"}`;code-block.js:1:11 lint/nursery/noUnnecessaryTemplateExpression FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This template expression is unnecessary.
> 1 │ const b = `${“world”}`;
│ ^^^^^^^^^^^^
2 │
ℹ The template only contains string literal expressions. A regular string literal can be used instead.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Safe fix: Replace the template expression with a string literal.
1 │ const·b·=·`${“world”}`;
│ --- --
const c = `${'hello'}${'world'}`;code-block.js:1:11 lint/nursery/noUnnecessaryTemplateExpression FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This template expression is unnecessary.
> 1 │ const c = `${‘hello’}${‘world’}`;
│ ^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ The template only contains string literal expressions. A regular string literal can be used instead.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Safe fix: Replace the template expression with a string literal.
1 │ - const·c·=·`${‘hello’}${‘world’}`;
1 │ + const·c·=·“helloworld”;
2 2 │
const d = `prefix_${'suffix'}`;code-block.js:1:11 lint/nursery/noUnnecessaryTemplateExpression FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This template expression is unnecessary.
> 1 │ const d = `prefix_${‘suffix’}`;
│ ^^^^^^^^^^^^^^^^^^^^
2 │
ℹ The template only contains string literal expressions. A regular string literal can be used instead.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Safe fix: Replace the template expression with a string literal.
1 │ - const·d·=·`prefix_${‘suffix’}`;
1 │ + const·d·=·“prefix_suffix”;
2 2 │
// Template with a non-string-literal expressionconst a = `${someVariable}`;// Template with a non-string-literal interpolation mixed with textconst b = `Hello, ${name}!`;// Tagged templates are never flaggedconst c = html`${'foo'}`;// Templates with newlines in the text part need the template syntaxconst d = `line one${'line two'}`;Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.