src/content/docs/linter/rules/no-template-curly-in-string.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.9.3` - Diagnostic Category: [`lint/suspicious/noTemplateCurlyInString`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`no-template-curly-in-string`](https://eslint.org/docs/latest/rules/no-template-curly-in-string){
"linter": {
"rules": {
"suspicious": {
"noTemplateCurlyInString": "error"
}
}
}
}
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.
const a = "Hello ${name}!";
const a = 'Hello ${name}!';
const a = "Time: ${12 * 60 * 60 * 1000}";
const a = `Hello ${name}!`;
const a = `Time: ${12 * 60 * 60 * 1000}`;
const a = templateFunction`Hello ${name}`;