Unexpected template string expression. Open
tagFormat: '${version}',
- Read upRead up
- Exclude checks
title: no-template-curly-in-string
rule_type: problem
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.
Rule Details
This 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.
Examples
Examples of incorrect code for this rule:
::: incorrect
/*eslint no-template-curly-in-string: "error"*/
"Hello ${name}!";
'Hello ${name}!';
"Time: ${12 * 60 * 60 * 1000}";
:::
Examples of correct code for this rule:
::: correct
/*eslint no-template-curly-in-string: "error"*/
`Hello ${name}!`;
`Time: ${12 * 60 * 60 * 1000}`;
templateFunction`Hello ${name}`;
:::
When Not To Use It
This rule should not be used in ES3/5 environments. Source: http://eslint.org/docs/rules/
Unexpected template string expression. Open
message: 'chore(release): set `package.json` to ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
- Read upRead up
- Exclude checks
title: no-template-curly-in-string
rule_type: problem
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.
Rule Details
This 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.
Examples
Examples of incorrect code for this rule:
::: incorrect
/*eslint no-template-curly-in-string: "error"*/
"Hello ${name}!";
'Hello ${name}!';
"Time: ${12 * 60 * 60 * 1000}";
:::
Examples of correct code for this rule:
::: correct
/*eslint no-template-curly-in-string: "error"*/
`Hello ${name}!`;
`Time: ${12 * 60 * 60 * 1000}`;
templateFunction`Hello ${name}`;
:::
When Not To Use It
This rule should not be used in ES3/5 environments. Source: http://eslint.org/docs/rules/