ESLint v10.0.0-alpha.0 发布

我们刚刚发布了 ESLint v10.0.0-alpha.0,这是 ESLint 的一次重大版本升级。此次发布增加了一些新功能,并修复了前一个版本中发现的几个错误。此次发布还有一些破坏性更改,因此请仔细阅读以下内容。

亮点

🌐 Highlights

此版本的 ESLint 尚未准备好用于生产环境,提供此版本是为了在发布最终版本之前收集社区的反馈。如果你遇到任何问题或有任何反馈,请通过在我们的 GitHub 仓库 创建问题告诉我们。

🌐 This version of ESLint is not ready for production use and is provided to gather feedback from the community before releasing the final version. Please let us know if you having any problems or feedback by creating issues on our GitHub repo.

此版本的大部分亮点都是重大更改,并在迁移指南中有更详细的讨论。下面是重大更改的摘要。(不太重要的更改包含在迁移指南中。)

🌐 Most of the highlights of this release are breaking changes, and are discussed further in the migration guide. There are summaries of the significant changes below. (Less significant changes are included in the migration guide.)

此 ESLint 预发布版本有一个单独的文档部分

🌐 This prerelease version of ESLint has a separate documentation section.

不再支持 Node.js < v20.19.0、v21、v23

🌐 Node.js < v20.19.0, v21, v23 no longer supported

截至本帖发布时,Node.js v22.x 是 LTS 版本,因此我们将 停止支持 所有早于 v20.19.0 的 Node.js 版本,以及 v21.x 和 v23.x。

🌐 As of this post, Node.js v22.x is the LTS release, and as such we are dropping support for all versions of Node.js prior to v20.19.0 as well as v21.x and v23.x.

ESLint v10.0.0 支持以下版本的 Node.js:

🌐 ESLint v10.0.0 supports the following versions of Node.js:

  • Node.js v20.19.0 及以上版本
  • Node.js v22.13.0 及以上版本
  • Node.js v24 及以上版本

新的配置文件查找算法

🌐 New configuration file lookup algorithm

ESLint v10.0.0 通过从每个被 lint 的文件所在目录开始 来定位 eslint.config.*,而不是像 ESLint v9.x 那样使用当前工作目录。新的行为允许在同一次运行中使用多个配置文件,这在单一仓库(monorepo)设置中特别有用。

🌐 ESLint v10.0.0 locates eslint.config.* by starting from the directory of each linted file rather than the current working directory as it was the case with ESLint v9.x. The new behavior allows for using multiple configuration files in the same run and can be particularly useful in monorepo setups.

在 ESLint v9.x 中,这种配置查找行为可以通过 v10_config_lookup_from_file 功能标志启用。在 ESLint v10.0.0 中,这种行为现在是默认的,并且 v10_config_lookup_from_file 标志已被移除。

🌐 In ESLint v9.x, this config lookup behavior could be enabled with the v10_config_lookup_from_file feature flag. In ESLint v10.0.0, this behavior is now the default and the v10_config_lookup_from_file flag has been removed.

已移除 eslintrc 功能

🌐 Removed eslintrc functionality

正如在 Flat 配置推出计划中宣布的,eslintrc 配置系统已在 ESLint v10.0.0 中被完全移除。具体来说,这意味着:

🌐 As announced in Flat config rollout plans, the eslintrc config system has been completely removed in ESLint v10.0.0. Specifically, this means:

  1. ESLINT_USE_FLAT_CONFIG 环境变量不再被遵守。
  2. CLI 不再支持 eslintrc 特定的参数(--no-eslintrc--env--resolve-plugins-relative-to--rulesdir--ignore-path)。
  3. .eslintrc.*.eslintignore 文件将不再被认可。
  4. /* eslint-env */ 评论被报告为错误。
  5. loadESLint() 函数现在总是返回 ESLint 类。
  6. Linter 构造函数的 configType 参数只能是 "flat",如果传入 "eslintrc" 会抛出错误。
  7. 以下 Linter eslintrc 特定的方法已被移除:
    • defineParser()
    • defineRule()
    • defineRules()
    • getRules()
  8. /use-at-your-own-risk 入口点的以下更改:
    • LegacyESLint 已被移除
    • FileEnumerator 已被移除
    • shouldUseFlatConfig() 函数将始终返回 true

Jiti < v2.2.0 不再支持

🌐 Jiti < v2.2.0 no longer supported

ESLint v10.0.0 在加载 TypeScript 配置文件时不再支持 jiti 2.2.0 之前的版本,因为已知问题可能导致在加载某些插件时出现兼容性问题。

🌐 ESLint v10.0.0 drops support for jiti versions prior to 2.2.0 when loading TypeScript configuration files due to known issues that can cause compatibility problems when configurations load certain plugins.

已更新 eslint:recommended

🌐 Updated eslint:recommended

eslint:recommended 配置已更新以包含我们认为重要的新规则

🌐 The eslint:recommended configuration is updated to include new rules that we feel are important.

已移除已弃用的规则 context 成员

🌐 Removed deprecated rule context members

以下规则 context 的成员不再可用:

🌐 The following rule context members are no longer available:

  • context.getCwd() - 请改用 context.cwd
  • context.getFilename() - 请改用 context.filename
  • context.getPhysicalFilename() - 请改用 context.physicalFilename
  • context.getSourceCode() - 请改用 context.sourceCode
  • context.parserOptions - 使用 context.languageOptionscontext.languageOptions.parserOptions 替代
  • context.parserPath - 无替换

尚未更新其代码的插件用户可以在此期间使用@eslint/compat工具。

🌐 Users of plugins that haven’t updated their code yet can use the @eslint/compat utility in the meantime.

已移除不推荐使用的 LintMessage#nodeTypeTestCaseError#type 属性

🌐 Removed deprecated LintMessage#nodeType and TestCaseError#type properties

在 ESLint v10.0.0 中,LintMessage 对象上的已弃用属性 nodeType 已被移除。相应地,RuleTester 不再接受 invalid 测试用例的 errors 中已弃用的 type 属性。

🌐 In ESLint v10.0.0, the deprecated nodeType property on LintMessage objects has been removed. Correspondingly, RuleTester no longer accepts the deprecated type property in errors of invalid test cases.

Program AST 节点范围覆盖整个源文本

🌐 Program AST node range spans entire source text

从 ESLint v10.0.0 开始,Program AST 节点的范围覆盖整个源文本。之前,前导和尾随的注释/空白不包括在范围内。

🌐 Starting with ESLint v10.0.0, Program AST node’s range spans the entire source text. Previously, leading and trailing comments/whitespace were not included in the range.

默认解析器(espree已更新。自定义解析器也应相应地进行更新。

🌐 The default parser (espree) has already been updated. Custom parsers are expected to be updated accordingly.

ScopeManager 实现的新要求

🌐 New requirements for ScopeManager implementations

从 ESLint v10.0.0 开始,自定义 ScopeManager 实现必须 自动解析代码中声明的全局变量的引用,包括 varfunction 声明,并提供一个实例方法 addGlobals(names: string[]),该方法在全局作用域中创建具有指定名称的变量并解析对它们的引用。

🌐 Starting with ESLint v10.0.0, custom ScopeManager implementations must automatically resolve references to global variables declared in the code, including var and function declarations, and provide an instance method addGlobals(names: string[]) that creates variables with the given names in the global scope and resolves references to them.

默认的 ScopeManager 实现 (eslint-scope) 已更新。自定义 ScopeManager 实现预计也应进行相应更新。

🌐 The default ScopeManager implementation (eslint-scope) has already been updated. Custom ScopeManager implementations are expected to be updated accordingly.

正在安装

🌐 Installing

由于这是预发布版本,npm 不会自动升级。安装时必须指定 next 标签:

🌐 Since this is a pre-release version, you will not automatically be upgraded by npm. You must specify the next tag when installing:

npm i eslint@next --save-dev

你也可以直接指定版本:

🌐 You can also specify the version directly:

npm i eslint@10.0.0-alpha.0 --save-dev

迁移指南

🌐 Migration Guide

由于有很多变化,我们创建了一个 迁移指南,详细描述了重大更改以及你应该采取的应对步骤。我们预计大多数用户应该能够在不更改构建的情况下升级,但如果遇到问题,迁移指南应该是一个有用的资源。

🌐 As there are a lot of changes, we’ve created a migration guide describing the breaking changes in great detail along with the steps you should take to address them. We expect that most users should be able to upgrade without any build changes, but the migration guide should be a useful resource if you encounter problems.

重大更改

🌐 Breaking Changes

  • 96512a6 修复!: 移除已废弃的规则上下文方法 (#20086) (Nicholas C. Zakas)
  • c69fdac 功能更新!: 移除 eslintrc 支持 (#20037) (Francesco Trotta)
  • 208b5cc 功能更新!: 使用 ScopeManager#addGlobals() (#20132) (Milos Djermanovic)
  • a2ee188 修复!: 在 no-invalid-regexp 选项中添加 uniqueItems: true (#20155) (Tanuj Kanti)
  • a89059d 功能更新!: 程序范围遍及整个源文本 (#20133) (Pixel998)
  • 39a6424 修复!: 确保在所有 RuleFixer 方法中 ‘text’ 是字符串 (#20082) (Pixel998)
  • f28fbf8 修复!: 弃用 radix 规则的 "always""as-needed" 选项 (#20223) (Milos Djermanovic)
  • aa3fb2b 修复!: 收紧 func-names 模式 (#20119) (Pixel998)
  • f6c0ed0 功能更新!:将 eslint-env 评论报告为错误 (#20128) (Francesco Trotta)
  • 4bf739f 修复!: 移除已弃用的 LintMessage#nodeTypeTestCaseError#type (#20096) (Pixel998)
  • 523c076 特性!: 放弃对 jiti < 2.2.0 的支持 (#20016) (michael faith)
  • 454a292 功能更新!: 更新 eslint:recommended 配置 (#20210) (Pixel998)
  • 4f880ee 特性!: 移除 v10_* 和非活动的 unstable_* 标志 (#20225) (sethamus)
  • f18115c 功能更新!: no-shadow-restricted-names 默认报告 globalThis (#20027) (sethamus)
  • c6358c3 增强功能!: 需要 Node.js ^20.19.0 || ^22.13.0 || >=24 (#20160) (Milos Djermanovic)

文档

🌐 Documentation

  • 4b5dbcd 文档:重排 v10 迁移指南 (#20315) (Milos Djermanovic)
  • 5d84a73 文档:更新自述文件(GitHub Actions 机器人)
  • 37c8863 文档:修复 v10 迁移指南中的错误锚点链接 (#20299) (Pixel998)
  • 077ff02 文档:添加迁移到 10.0.0 文档 (#20143) (唯然)
  • 3822e1b 文档:更新自述文件(GitHub Actions 机器人)

杂项

🌐 Chores

  • 1e2cad5 事务:更新 package.json 以适配 @eslint/js 版本发布(Jenkins)
  • 9da2679 事务: 更新 @eslint/* 依赖 (#20321) (Milos Djermanovic)
  • 0439794 重构:使用 @eslint/core 的类型 (#20235) (jaymarvelz)
  • cb51ec2 测试:清理 SourceCode#traverse 测试 (#20289) (Milos Djermanovic)
  • 897a347 事务: 在规则测试中移除对 type 的限制 (#20305) (Pixel998)
  • d972098 例行任务:在 Renovate 中忽略 Prettier 更新以保持与主干同步 (#20304) (Pixel998)
  • a086359 任务:移除多余的 fast-glob 开发依赖 (#20301) (루밀LuMir)
  • 564b302 事务: 安装 prettier 作为开发依赖 (#20302) (michael faith)
  • 8257b57 重构:纠正 eslint-plugin/report-message-format 的正则表达式 (#20300) (루밀LuMir)
  • e251671 重构:在 RuleTester 中提取断言 (#20135) (唯然)
  • 2e7f25e 杂务:将 legacy-peer-deps 添加到 .npmrc (#20281) (Milos Djermanovic)
  • 39c638a 杂务:更新 eslint-config-eslint 依赖以支持 v10 预发布版本 (#20278) (Milos Djermanovic)
  • 8533b3f 杂项:将依赖 @eslint/json 更新到 ^0.14.0 (#20288) (renovate[bot])
  • 796ddf6 杂项:将依赖 @eslint/js 更新到 ^9.39.1 (#20285) (renovate[bot])

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