eslint/prefer-template 风格
它的作用
要求使用模板字面量代替字符串拼接。
为什么这是不好的?
在 ES2015 (ES6) 中,我们可以使用模板字面量来替代字符串拼接。
示例
此规则的 错误 代码示例:
js
const str = "Hello, " + name + "!";
const str1 = "Time: " + 12 * 60 * 60 * 1000;此规则的 正确 代码示例:
js
const str = "Hello World!";
const str2 = `Time: ${12 * 60 * 60 * 1000}`;
const str4 = "Hello, " + "World!";如何使用
通过配置文件或命令行工具 启用 此规则,可以使用:
json
{
"rules": {
"prefer-template": "error"
}
}bash
oxlint --deny prefer-template