
亮点
🌐 Highlights
新解析器选项
🌐 New Parser Option
默认解析器有一个新选项 allowReserved(布尔值,默认 false)。当设置为 true 时,保留字可以用作标识符。
🌐 The default parser has a new option allowReserved (boolean, default false). When set to true, reserved words can be used as identifiers.
此选项只能与 "ecmaVersion": 3 一起使用。
🌐 This option can only be used with "ecmaVersion": 3.
{
"parserOptions": {
"ecmaVersion": 3,
"allowReserved": true
}
}
自定义格式器的新功能
🌐 New Features for Custom Formatters
此版本为自定义格式化程序添加了两个新功能。
🌐 This release adds two new features for custom formatters.
异步格式化器
🌐 Async Formatters
现在允许格式化程序返回 Promise<string>。也就是说,格式化程序可以是异步函数。
🌐 Formatters are now allowed to return Promise<string>. That is, a formatter can be an async function.
//------ my-formatter.js ------
module.exports = async function(results, context) {
const something = await getSomethingAsync();
// ...
return formattedResults;
};
context.cwd
context 参数有一个新的属性 cwd(字符串,绝对路径)。它表示用于 lint 的工作目录。该值来自 ESLint 类的 cwd 构造选项,格式化程序可以使用它比使用 process.cwd() 更可靠地输出相对路径。
🌐 The context argument has a new property cwd (string, absolute path). It represents the working directory used for linting. This value comes from the cwd constructor option of the ESLint class, and formatters can use it to output relative paths more reliably than by using process.cwd().
//------ my-formatter.js ------
module.exports = function(results, context) {
const cwd = context.cwd;
// ...
};
特性
🌐 Features
5771663功能:添加allowReserved解析器选项 (#15387) (Milos Djermanovic)[32ac37a](https://github.com/eslint/eslint/commit/32ac37a76b2e009a8f106229bc7732671d358189)功能:Linter 中的扁平配置支持(参考#13481) (#15185)(Nicholas C. Zakas)d041f34功能:在 no-constant-condition 中将 Class/New 表达式视为真值 (#15326) (Jordan Eldredge)[8f44cf5](https://github.com/eslint/eslint/commit/8f44cf505765b663e371412ab57f0f1dbbe78513)功能:仅报告超过max-lines-per-function限制的行 (#15140) (Sneh Khatri)808ad35功能:将 cwd 传递给格式化程序(参考 eslint/rfcs#57) (#13392) (Toru Nagashima)f1b7499功能:支持异步格式化器 (#15243) (MO)
错误修复
🌐 Bug Fixes
文档
🌐 Documentation
54deec5文档:更新 integrations.md (#15380) (Vlad Sholokhov)fa0423a文档:修复 PR 模板中的拼写错误 (#15365) (Nitin Kumar)e233920文档:启用更多的 markdownlint 规则并修复违规 (#15368) (Bryan Mishkin)632176d文档:在 getter-return 文档中取消不必要缩进的示例 (#15363) (Jordan Eldredge)4497e88文档:更新发布说明博客文章模板 (#15285) (Nicholas C. Zakas)
杂项
🌐 Chores
efede90事务: 升级 @eslint/eslintrc@1.0.5 (#15389) (Milos Djermanovic)0b8c846杂务:修复 update-readme 以避免多个连续的空行 (#15375) (Milos Djermanovic)94b2a8b事务: 在 M1 Mac 测试中使用默认的 Chromium 二进制文件 (#15371) (Brandon Mills)ba58d94ci: 使用节点v16来验证文件 (#15364) (Nitin Kumar)1e32ee5工作:为规则添加 jsdoc 类型注解 (#15291) (Bryan Mishkin)
