noTemplateCurlyInString
このコンテンツはまだ日本語訳がありません。
Diagnostic Category: lint/nursery/noTemplateCurlyInString
Since: v1.9.3
Sources:
- Same as:
no-template-curly-in-string
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.
Examples
Section titled ExamplesInvalid
Section titled Invalidconst 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.
Valid
Section titled Validconst a = `Hello ${name}!`;const a = `Time: ${12 * 60 * 60 * 1000}`;
const a = templateFunction`Hello ${name}`;