]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/no-template-curly-in-string.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / no-template-curly-in-string.md
CommitLineData
eb39fafa
DC
1# Disallow template literal placeholder syntax in regular strings (no-template-curly-in-string)
2
3ECMAScript 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.
4
eb39fafa
DC
5## Rule Details
6
7This rule aims to warn when a regular string contains what looks like a template literal placeholder. It will warn when it finds a string containing the template literal placeholder (`${something}`) that uses either `"` or `'` for the quotes.
8
9## Examples
10
11Examples of **incorrect** code for this rule:
12
13```js
14/*eslint no-template-curly-in-string: "error"*/
15"Hello ${name}!";
16'Hello ${name}!';
17"Time: ${12 * 60 * 60 * 1000}";
18```
19
20Examples of **correct** code for this rule:
21
22```js
23/*eslint no-template-curly-in-string: "error"*/
24`Hello ${name}!`;
25`Time: ${12 * 60 * 60 * 1000}`;
26
27templateFunction`Hello ${name}`;
28```
29
30## When Not To Use It
31
32This rule should not be used in ES3/5 environments.