ESLint v8.4.0 发布

我们刚刚发布了 ESLint v8.4.0,这是 ESLint 的一次小版本升级。此版本添加了一些新功能,并修复了上一版本中发现的几个错误。

亮点

🌐 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

  • 4940cc5 修复:在 CLI 文档中将 --rulesdir 选项标记为已弃用 (#15310) (Kevin Partington)

文档

🌐 Documentation

杂项

🌐 Chores

  • efede90 事务: 升级 @eslint/eslintrc@1.0.5 (#15389) (Milos Djermanovic)
  • 0b8c846 杂务:修复 update-readme 以避免多个连续的空行 (#15375) (Milos Djermanovic)
  • 94b2a8b 事务: 在 M1 Mac 测试中使用默认的 Chromium 二进制文件 (#15371) (Brandon Mills)
  • ba58d94 ci: 使用节点 v16 来验证文件 (#15364) (Nitin Kumar)
  • 1e32ee5 工作:为规则添加 jsdoc 类型注解 (#15291) (Bryan Mishkin)

最新的 ESLint 新闻、案例研究、教程和资源。

ESLint v10.3.0 发布
1 min read

ESLint v10.3.0 发布

我们刚刚发布了 ESLint v10.3.0,这是 ESLint 的一次小版本升级。此版本添加了一些新功能,并修复了上一版本中发现的几个错误。

ESLint v10.2.1 发布
1 min read

ESLint v10.2.1 发布

我们刚刚发布了 ESLint v10.2.1,这是 ESLint 的一个补丁版本升级。本次发布修复了上一版本中发现的几个错误。

ESLint v10.2.0 发布
2 min read

ESLint v10.2.0 发布

我们刚刚发布了 ESLint v10.2.0,这是 ESLint 的一次小版本升级。此版本添加了一些新功能,并修复了上一版本中发现的几个错误。