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 Invalidcode-block.js:1:18 lint/nursery/noTemplateCurlyInString ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Unexpected template string placeholder.
> 1 │ const a = “Hello ${name}!”;
│ ^^^^^^^
2 │
ℹ Turn the string into a template string.
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.
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.