首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

no-template-curly-in-string

ECMAScript 6 允许程序员使用模板文字创建包含变量或表达式的字符串,而不是字符串连接,通过${variable}在两个反引号引号(). 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}”)之间编写表达式而不是包含注入的表达式。

规则细节

此规则旨在警告常规字符串包含看起来像模板字面占位符的内容。它会在发现一个包含模板文字 place holder(${something})的字符串时发出警告,该字符串使用引号"'引号。

例子

此规则的错误代码示例:

代码语言:javascript
复制
/*eslint no-template-curly-in-string: "error"*/
"Hello ${name}!";
'Hello ${name}!';
"Time: ${12 * 60 * 60 * 1000}";

此规则的正确代码示例:

代码语言:javascript
复制
/*eslint no-template-curly-in-string: "error"*/
`Hello ${name}!`;
`Time: ${12 * 60 * 60 * 1000}`;

templateFunction`Hello ${name}`;

何时不使用它

此规则不应用于ES3 / 5环境。

版本

这条规则是在 ESLint 3.3.0 中引入的。

资源

扫码关注腾讯云开发者

领取腾讯云代金券