unicorn/consistent-template-literal-escape

Enforce one way to escape ${ in template literals

fixable

To write a literal ${ in a template literal you need to escape it, and three spellings work: a backslash before the $, before the {, or before both. All three give the same string. This rule keeps the first one, \${, so an escaped placeholder looks the same everywhere.

Tagged templates aren't checked, because a tag can read the raw text.

--fix rewrites the escape.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"unicorn/consistent-template-literal-escape" = "error" # or "warn"

Examples#

example.js2 problems
const usage = `Write $\{name} to insert the name`;
const help = `Write \$\{name} to insert the name`;
example.jsNo problems
const usage = `Write \${name} to insert the name`;
example.jsNo problems
const pattern = String.raw`$\{name}`;