ESLint v10.7.0 发布

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

亮点

🌐 Highlights

max-nested-callbacks 中的新选项 checkConstructorCallCallbacks

🌐 New option checkConstructorCallCallbacks in max-nested-callbacks

max-nested-callbacks 规则现在支持 checkConstructorCallCallbacks 选项。 启用后,该规则在计算嵌套深度时,也会统计通过 new 传递给构造函数调用的回调函数,例如 new Promise((resolve) => {})

🌐 The max-nested-callbacks rule now supports a checkConstructorCallCallbacks option. When enabled, the rule also counts callback functions passed to constructor calls with new, such as new Promise((resolve) => {}), when calculating nesting depth.

例如,对于 { "max": 1, "checkConstructorCallCallbacks": true },该规则会报告以下代码超出了允许的回调嵌套深度:

🌐 For example, with { "max": 1, "checkConstructorCallCallbacks": true }, the rule reports the following code as exceeding the allowed callback nesting depth:

run(() => {
    new Promise(resolve => resolve());
});

preserve-caught-error 中的新选项 errorClassNames

🌐 New option errorClassNames in preserve-caught-error

preserve-caught-error 规则现在支持 errorClassNames 选项。 此选项允许你通过将捕获的原始错误作为原因传递,来指定必须保留原始捕获错误的其他自定义错误类名。

🌐 The preserve-caught-error rule now supports an errorClassNames option. This option lets you specify additional custom error class names that must preserve the original caught error by passing it as a cause.

例如,对于 { "errorClassNames": ["MyError"] },下面的代码会被报告,因为抛出的 MyError 没有将原始错误包含为原因,就像内置的错误类型必须做的一样:

🌐 For example, with { "errorClassNames": ["MyError"] }, the following code is reported because the thrown MyError does not include the original error as a cause, just like built-in error types must:

try {
    doSomething();
} catch (error) {
    throw new MyError("something went wrong");
}

no-compare-neg-zero 的建议

🌐 Suggestions for no-compare-neg-zero

[no-compare-neg-zero](/docs/latest/rules/no-compare-neg-zero) 规则现在支持建议。在适当的情况下,它会建议将 -0 替换为 0,或在像 ===!== 这样的运算符上使用 Object.is()。 例如,对于像 x === -0 这样的表达式,该规则建议使用 x === 0 以保留现有的比较行为,以及使用 Object.is(x, -0) 来区分 -0+0

🌐 The no-compare-neg-zero rule now supports suggestions. Where appropriate, it suggests replacing -0 with 0 or using Object.is() instead of operators such as === or !==. For example, for an expression such as x === -0, the rule suggests x === 0 to preserve the existing comparison behavior, and Object.is(x, -0) to distinguish -0 from +0.

特性

🌐 Features

错误修复

🌐 Bug Fixes

文档

🌐 Documentation

  • c30d808 文档:更新自述文件(GitHub Actions 机器人)
  • 5139800 文档:在 v9 和 v10 指南中记录 ESLint 迁移代码修改工具 (#20980) (Alex Bit)
  • 04174cb 文档:更新自述文件(GitHub Actions 机器人)
  • 026e130 文档:更新错误修复的语义化版本策略 (#21048) (Milos Djermanovic)
  • 9d42fef 文档:更新自述文件(GitHub Actions 机器人)
  • b230159 文档:更新自述文件(GitHub Actions 机器人)
  • 0129972 文档:在配置文件指南中将 **/.js 通配符更正为 **/*.js (#21036) (EduardF1)

杂项

🌐 Chores

  • 9489379 事务: 更新依赖 @eslint/eslintrc 到 ^3.3.6 (#21076) (renovate[bot])
  • 81a4774 事务: v9.39.5 版本更新 (Jenkins)
  • 9835414 杂项:在所有 TypeScript 文件中启用 $ExpectType 注解 (#21071) (Francesco Trotta)
  • 72adf6b 杂项:在 renovate 中限制 markdownlint-cli2 更新 (#21067) (lumir)
  • 833ec10 杂务:将依赖 prettier 更新到 v3.9.4 (#21061) (renovate[bot])
  • 7ea106d 杂项:更新生态系统插件 (#21059) (ESLint 机器人)
  • 8fb550e 任务: 向 .git-blame-ignore-revs 添加 prettier 更新提交 (#21056) (lumir)
  • e4e1166 杂务:将依赖 prettier 更新到 v3.9.1 (#21055) (renovate[bot])
  • 0493f53 杂项:将 prettier 更新到 v3.9.0 (#21054) (Pixel)
  • 1056a99 杂务:将依赖 prettier 更新到 v3.8.5 (#21049) (renovate[bot])
  • 4d4155d ci:在拉取请求上运行生态系统测试 (#21027) (sethamus)
  • 993539f 事务: 更新依赖 @eslint/json 到 ^2.0.1 (#21042) (renovate[bot])
  • 53f8b69 测试:向 no-constant-binary-expression 添加错误位置 (#21039) (lumir)
  • 5ab71d5 重构:清理 radix 规则内部 (#21015) (Pixel)
  • a80a9a4 例行任务:更新生态系统插件 (#21035) (ESLint 机器人)
  • 7c9a029 ci:在 CI 中添加 Node.js 26 (#20847) (lumir)

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

ESLint v10.8.0 发布
2 min read

ESLint v10.8.0 发布

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

ESLint v9.39.5 发布
1 min read

ESLint v9.39.5 发布

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