ESLint v9.37.0 发布

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

亮点

🌐 Highlights

no-restricted-imports 中的 allowTypeImports 选项

🌐 allowTypeImports option in no-restricted-imports

[no-restricted-imports](/docs/latest/rules/no-restricted-imports) 规则现在支持 allowTypeImports 选项。当设置为 true 时,这将允许在 TypeScript 文件中进行仅类型导入,同时仍然禁止普通导入。

🌐 The no-restricted-imports rule now supports the allowTypeImports option. When set to true, this will allow type-only imports in TypeScript files while still disallowing regular imports.

例如,以下规则设置只允许从 node:assert 模块进行仅类型导入:

🌐 For example, the following rule setting permits only type-only imports from the node:assert module:

/*
    eslint no-restricted-imports: ["error", {
        name: "node:assert",
        allowTypeImports: true,
    }]
*/

import assert from "node:assert"; // ❌ Incorrect

import type { AssertionError } from "node:assert"; // ✅ Correct

这将 no-restricted-imports 规则与 相应的 typescript-eslint 规则 对齐,并继续 ESLint 在核心规则中扩展 TypeScript 语法支持的持续努力。

🌐 This aligns the no-restricted-imports rule with the corresponding typescript-eslint rule, and continues ESLint’s ongoing efforts to extend TypeScript Syntax support in core rules.

--concurrency=auto 的改进启发式方法

🌐 Improved heuristic for --concurrency=auto

ESLint v9.34.0 引入多线程 linting 之后,一些使用 --cache 标志运行 ESLint 的用户报告说,与不设置 --concurrency 选项相比,使用 --concurrency=auto 时性能更慢。

🌐 After the introduction of multithreaded linting in ESLint v9.34.0, some users running ESLint with the --cache flag reported slower performance when using --concurrency=auto compared to leaving the --concurrency option unset.

慢速发生是因为即使大多数结果已经被缓存,ESLint 有时也会启用多线程模式,从而增加了不必要的开销。

🌐 The slowdown occurred because ESLint would sometimes enable multithread mode even when most results were already cached, adding unnecessary overhead.

这个行为已在 ESLint v9.37.0 中得到纠正,其中 --concurrency=auto 的启发式已得到改进,以更好地考虑增加并行性没有带来好处的情况。

🌐 This behavior has been corrected in ESLint v9.37.0, where the heuristic for --concurrency=auto has been improved to better account for cases where increased parallelism provides no benefit.

preserve-caught-error 识别计算的 cause 属性

🌐 preserve-caught-error recognizes computed cause property

现在 preserve-caught-error 规则可以正确处理在抛出错误中使用计算属性语法表达的 cause 选项的情况。例如:

🌐 The preserve-caught-error rule now correctly handles cases where the cause option in a thrown error is expressed using computed property syntax. For example:

try {
    // ...
} catch (error) {
    throw new Error("Unexpected error!", { ["cause"]: error });
}

特性

🌐 Features

错误修复

🌐 Bug Fixes

文档

🌐 Documentation

  • b950359 文档:修复文档中的拼写错误 (#20182) (루밀LuMir)
  • 42498a2 文档:通过隐藏非语义字符改进目录可访问性 (#20181) (Percy Ma)
  • 29ea092 文档:更新自述文件(GitHub Actions 机器人)
  • 5c97a04 文档:在已弃用规则横幅中显示 availableUntil (#20170) (Pixel998)
  • 90a71bf 文档:更新 README 文件以添加徽章和说明 (#20115) (루밀LuMir)
  • 1603ae1 文档:将引用从 master 更新为 main (#20153) (루밀LuMir)

杂项

🌐 Chores

  • afe8a13 杂务:将 @eslint/js 依赖更新到版本 9.37.0 (#20183) (Francesco Trotta)
  • abee4ca 事务:更新 package.json 以适配 @eslint/js 版本发布(Jenkins)
  • fc9381f 任务:修复评论中的拼写错误 (#20175) (overlookmotel)
  • e1574a2 任务:取消固定 jiti (#20173) (renovate[bot])
  • e1ac05e 重构:将 ESLint.findConfigFile() 标记为 async,添加缺失的文档 (#20157) (Pixel998)
  • 347906d 杂务:更新 eslint (#20149) (renovate[bot])
  • 0cb5897 测试:删除在多线程模式测试中为循环修复创建的临时目录 (#20146) (Milos Djermanovic)
  • bb99566 ci:将 jiti 固定到版本 2.5.1 (#20151) (Pixel998)
  • 177f669 perf:改进 "auto" 并发的工作线程数量计算 (#20067) (Francesco Trotta)
  • 448b57b 任务:将已废弃的格式规则标记为在 v11.0.0 之前可用 (#20144) (Milos Djermanovic)

最新的 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 的一次小版本升级。此版本添加了一些新功能,并修复了上一版本中发现的几个错误。