平面配置部署计划

我们已经在新的配置系统上工作了好几年。这是我们计划推出它的方式。

这可能难以置信,但 ESLint 新配置系统的 RFC,昵称为 flat config,最早是在 2019 年写的。我们一直到 2022 年 (v8.21.0) 才发布了一个实验性的、可选择使用的 flat config 版本。从那时起,我们一直根据社区的反馈进行更改和改进。计划一直是允许当前的配置系统,昵称为 eslintrc,与 flat config 并行存在一段时间,以便为 ESLint 用户提供平稳的过渡。现在 flat config 功能已经完整,我们很高兴分享推出计划。

🌐 It may seem hard to believe, but the RFC for ESLint’s new configuration system, nicknamed flat config, was first written in 2019. It took until 2022 (v8.21.0) for us to release an experimental, opt-in version of flat config. Since then, we’ve been making changes and improvements based on feedback from the community. The plan was always to allow the current configuration system, nicknamed eslintrc, to exist alongside flat config for a period of time to allow a smooth transition for ESLint users. With flat config now feature complete, we are happy to share the rollout plan.

ESLint v9.0.0 默认的扁平配置

🌐 Flat config by default in ESLint v9.0.0

当 ESLint v9.0.0 发布时,不管是在今年年底还是明年年初,flat 配置将成为默认的配置系统,我们将弃用(但不会移除)eslintrc。新功能将只为 flat 配置添加,因此我们鼓励每个人尽快放弃 eslintrc,以便充分利用 v9.0.0 提供的所有功能。

🌐 When ESLint v9.0.0 is released, either the end of this year or beginning of next year, flat config will be the default configuration system and we will deprecate, but not remove, eslintrc. New features will be added only for flat config, so we encourage everyone to move off of eslintrc as quickly as possible to take advantage of everything v9.0.0 will offer.

这项变化对你的意义取决于你如何使用 ESLint,如果你有任何问题或顾虑,请前往我们的 Discord 与团队讨论。

🌐 What this change means for you depends on how you use ESLint, and if you have any questions or concerns, please stop by our Discord to discuss with the team.

对于 CLI 用户,这意味着几件事:

  • ESLint CLI 默认会搜索 eslint.config.js,而不是 .eslintrc.* 文件。
  • 如果未找到 eslint.config.js 文件,CLI 会将其视为错误并且不会运行。
  • 如果你想使用 eslintrc,你需要将 ESLINT_USE_FLAT_CONFIG 环境变量设置为 false。当你这样做时,你会在控制台中收到一个弃用警告。

对于规则开发者RuleTester 类将等同于当前的 FlatRuleTester 类。如果你在规则测试中传递了任何解析器相关选项,你需要更新这些选项以符合扁平配置格式。

你还应确保你的规则没有使用 context.parserOptionscontext.parserPath。相反,你应该使用 context.languageOptionscontext.languageOptions.parser,它们在 ESLint 以 eslintrc 模式运行时也能起作用。有关更多信息,请参阅我们的上一篇文章

🌐 You should also make sure that your rules aren’t using context.parserOptions and context.parserPath. Instead, you should be using context.languageOptions and context.languageOptions.parser, which also work when ESLint is run in eslintrc mode. See our previous post for more information.

对于可共享配置的作者,你应该将你的可共享配置更新为使用平面配置格式。这包括将引用的插件从 package.jsonpeerDependencies 部分移动到 dependencies 部分。

对于插件开发者,你应该更新导出的 configs 以使用扁平配置格式。插件的其余部分,包括 rulesprocessors,不需要任何更改。更多详情请参见 插件迁移指南

对于API用户,你需要决定是否希望在短期内支持这两种配置系统。v9.0.0中的API将发生以下变化:

  • ESLint 类现在将在 v8.x 中等同于 FlatESLint 类。除了少数几个选项之外,这应该大部分是一个透明的变化。

  • LegacyESLint 类仍将提供以允许访问 eslintrc 功能,但我们不会在 v9.x 中更新此类。所有新功能将仅针对基于平铺配置的 API 实现。

  • FlatESLint 类仍将提供,以避免不必要地破坏现有实现,但我们鼓励你尽快切换到 ESLint

  • shouldUseFlatConfig() 方法将返回 true,除非 ESLINT_USE_FLAT_CONFIG 环境变量为 false

  • Linter 类默认将切换到扁平配置模式,但你仍然可以通过在构造函数中将 configType 选项指定为 "eslintrc" 来设置使用 eslintrc,例如:

    const linter = new Linter({ configType: "eslintrc" });
    

eslintrc 在 ESLint v10.0.0 中被移除

🌐 eslintrc removed in ESLint v10.0.0

当 ESLint v10.0.0 发布时(很可能在 2024 年底或 2025 年初),eslintrc 配置系统将被完全移除。

🌐 When ESLint v10.0.0 is released (end of 2024 or early 2025 in all likelihood), the eslintrc configuration system will be completely removed.

对于 CLI 用户,这意味着几件事:

  • ESLint CLI 将搜索 eslint.config.js 而不是 .eslintrc.* 文件。
  • 如果未找到 eslint.config.js 文件,CLI 会将其视为错误并且不会运行。
  • ESLINT_USE_FLAT_CONFIG 环境变量将不再被支持,但不会抛出错误。
  • 特定于 eslintrc 配置文件的 CLI 选项将被移除。

对于规则开发者context.parserPathcontext.parserOptions 属性将被移除。

对于可共享配置的作者,在 v10.0.0 中没有额外的关注事项。

对于插件开发者,在 v10.0.0 中没有额外的顾虑。

对于 API 用户,你需要停止使用 /use-at-your-own-risk 入口点中的类。v10.0.0 版本的 API 将在以下方面发生变化:

  • ESLint 类现在将成为与核心交互的唯一方式。
  • LegacyESLint 类将被移除。
  • FlatESLint 类将被移除。
  • shouldUseFlatConfig() 方法将始终返回 true
  • Linter 类的 configType 构造函数选项将无效并抛出错误。

结论

🌐 Conclusion

在我们新的配置系统开发方面,我们已经取得了长足的进展,但仍然有很长的路要走。这是一次刻意缓慢的推出,以确保每个人都能舒适地更新他们的配置文件,尽量减少干扰。将整个生态系统转换到一个新的 API 是我们非常认真对待的责任,我们希望分阶段推出计划能够体现出这一点。你可以通过查看 实现问题 来继续关注我们的进展。如果你在本文中讨论的任何内容上需要帮助或有疑问,请 开始讨论 或访问 Discord 与团队交流。

🌐 We’ve come a long way in the development of our new configuration system and we still have a long way to go. This is an intentionally slow rollout to make sure that everyone can comfortably update their config files with as little disruption as possible. Shifting an entire ecosystem over to a new API is a responsibility we take seriously, and we hope that is evident in the phased rollout plan. You can continue to follow our progress by watching the implementation issue. If you need help with, or have questions about, any of what was discussed in this post, please start a discussion or stop by Discord to talk with the team.

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