
亮点
🌐 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 < v18.18.0 和 v19
🌐 Node.js < v18.18.0, v19 no longer supported
截至本帖发布,Node.js v20.x 是长期支持版本,因此我们将停止支持 所有 v18.18.0 之前的 Node.js 版本以及 v19.x。
🌐 As of this post, Node.js v20.x is the LTS release, and as such we are dropping support for all versions of Node.js prior to v18.18.0 as well as v19.x.
平面配置现在是默认配置,并且有一些变化
🌐 Flat config is now the default and has some changes
Flat 配置现在是 ESLint 的默认配置格式,eslintrc 已被正式弃用。要继续使用 eslintrc 配置文件,你需要将 ESLINT_USE_FLAT_CONFIG 环境变量设置为 false。
🌐 Flat config is now the default configuration format for ESLint and eslintrc is officially deprecated. To continue using a eslintrc configuration file, you’ll need to set the ESLINT_USE_FLAT_CONFIG environment variable to false.
此版本除了支持 eslint.config.js 外,还引入了对 eslint.config.mjs 和 eslint.config.cjs 的支持,使你可以更轻松地使用你偏好的模块格式,而不管包含包的模块格式如何。
🌐 This release introduces support for eslint.config.mjs and eslint.config.cjs in addition to eslint.config.js, making it easier to use the module format you’d prefer regardless of the module format of the containing package.
这一变化影响了用户、插件开发者和集成者,因为为了实现这一点,ESLint 的许多方面都必须进行更改。更多详情请参见我们之前的博客文章。
🌐 This change affects users, plugin developers, and integrators as many aspects of ESLint had to change to make this happen. Please see our previous blog post for more details.
移除了除 stylish、html、json 和 json-with-meta 外的所有格式化器
🌐 Removed all formatters except stylish, html, json, and json-with-meta
以下格式化工具已被移除:
🌐 The following formatters have been removed:
checkstylecompactjslint-xmljunittapunixvisualstudio
如果你当前正在使用这些格式化工具,则需要安装 独立包 以用于 ESLint v9.0.0。
🌐 If you are using these formatters currently, you’ll need to install the standalone packages for use with ESLint v9.0.0.
已移除 valid-jsdoc 和 require-jsdoc 规则
🌐 Removed valid-jsdoc and require-jsdoc rules
我们已移除 valid-jsdoc 和 require-jsdoc。我们建议改用 eslint-plugin-jsdoc 插件。
🌐 We have removed valid-jsdoc and require-jsdoc. We recommend using the eslint-plugin-jsdoc plugin instead.
移除了 context 和 SourceCode 上的不推荐使用的方法
🌐 Removed deprecated methods on context and SourceCode
正如我们在九月宣布的那样,我们已经从 context 中移除了许多已弃用的方法,并用 SourceCode 上的方法进行了替代。
🌐 As we announced in September, we have removed a lot of deprecated methods from context and replaced them with methods on SourceCode.
正在更新 eslint:recommended
🌐 Updating eslint:recommended
eslint:recommended 配置已更新,以包括我们认为重要的新规则,并删除已弃用和不那么重要的规则。
🌐 The eslint:recommended configuration is updated to include new rules that we feel are important, and to remove deprecated and less important rules.
规则书写方式的更改
🌐 Changes to how you write rules
我们进行了多项更改以帮助防止规则错误:
🌐 We’ve made multiple changes to help prevent errors in rules:
- 函数风格的规则将在 v9.0.0 中停止工作。函数风格的规则是通过从文件中导出一个函数而不是导出带有
create()方法的对象来创建的规则。 - 当规则没有指定
meta.schema时,将应用默认架构[]。这意味着没有架构的规则将被假定为没有选项,这反过来意味着如果提供了选项,验证将失败。 RuleTester现在严格检查同一 lint 问题的建议消息是否唯一,并确保建议生成有效的语法。
--quiet 选项性能更好
🌐 --quiet option is more performant
--quiet 选项会在 ESLint 控制台中隐藏所有警告。在 v9.0.0 中,我们通过不执行任何设置为 "warn" 的规则来进行性能改进。
🌐 The --quiet option hides all warnings in the ESLint console. In v9.0.0, we are making a performance improvement by also not executing any rules set to "warn".
运行 eslint 时没有文件参数
🌐 Running eslint with no file arguments
如果你使用扁平配置并且没有向 CLI 传递任何文件参数,CLI 将默认对当前目录进行 lint,这意味着你可以输入 npx eslint 并且它将直接工作。(使用 eslintrc 配置文件执行相同操作会导致错误。)
🌐 If you are using flat config and you don’t pass any file arguments to the CLI, the CLI will default to linting the current directory, which means you can type npx eslint and it will just work. (Doing the same with an eslintrc config file will result in an error.)
未使用的禁用指令默认会引发警告
🌐 Unused disable directives cause warnings by default
ESLint 长期以来就能够标记未使用的禁用指令。在此版本中,我们默认启用了对未使用禁用指令的警告。你可以在配置文件中使用 linterOptions.reportUnusedDisableDirectives 修改此值,或在命令行使用 --report-unused-disable-directives-severity 修改此值。
🌐 ESLint has long been able to flag unused disable directives. In this release, we’ve enabled warnings for unused disable directives by default. You can modify this value in your config file with linterOptions.reportUnusedDisableDirectives or on the command line using --report-unused-disable-directives-severity.
正在安装
🌐 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@9.0.0-alpha.0 --save-dev
重大更改
🌐 Breaking Changes
946ae00增强功能!: FlatRuleTester -> RuleTester (#17922) (Nicholas C. Zakas)baff28c功能更新!: 从eslint:recommended中移除no-inner-declarations(#17920) (Milos Djermanovic)cadfbcdfeat!: 将 FlatESLint 重命名为 ESLint (#17914) (Nicholas C. Zakas)d1018fc功能更新!: 在 --quiet 模式下跳过运行警告 (#17274) (Maddy Miller)fb81b1cfeat!: 设置默认schema: [],放弃对函数风格规则的支持 (#17792) (Milos Djermanovic)0b21e1f功能更新!: 为no-implicit-coercion添加两个更多用例 (#17832) (Gürgün Dayıoğlu)2916c63feat!: 默认将 Linter 切换为平面配置 (#17851) (Nicholas C. Zakas)200518e修复!:使用 parseListConfig 解析 ‘exported’ 注释 (#17675) (amondev)bdd6ba1功能更新!: 移除 valid-jsdoc 和 require-jsdoc (#17694) (Nicholas C. Zakas)12be307修复!:当未传递参数时 CLI 的行为 (#17644) (Nicholas C. Zakas)8fe8c56feat!: 更新 shouldUseFlatConfig 和 CLI,使平面配置成为默认 (#17748) (Nicholas C. Zakas)60dea3e功能更新!: 弃用 no-new-symbol,推荐使用 no-new-native-nonconstructor (#17710) (Francesco Trotta)5aa9c49功能更新!:检查建议修复中的解析错误 (#16639) (Bryan Mishkin)b3e0bb0增强功能!:在规则测试器中断言建议消息是唯一的 (#17532) (Josh Goldberg ✨)e563c52feat!:no-invalid-regexp使 allowConstructorFlags 区分大小写 (#17533) (Josh Goldberg ✨)e5f02c7修复!: no-sequences 规则模式修复 (#17878) (MHO)6ee3e9e功能更新!:更新eslint:recommended配置 (#17716) (Milos Djermanovic)c2cf85a功能更新!: 在扁平配置数组中放弃对字符串配置的支持 (#17717) (Milos Djermanovic)c314fd6功能更新!: 移除SourceCode#getComments()(#17715) (Milos Djermanovic)ae78ff1功能更新!: 移除已废弃的上下文方法 (#17698) (Nicholas C. Zakas)[f71c328](https://github.com/eslint/eslint/commit/f71c328e2786e2d73f168e43c7f96de172484a49)功能更新!: 在 API 中交换 FlatESLint-ESLint、FlatRuleTester-RuleTester (#17823) (Nicholas C. Zakas)5304da0功能更新!: 移除除 html、json(含元数据)和 stylish 之外的格式化器 (#17531) (Josh Goldberg ✨)e1e827f增强功能!: 需要 Node.js^18.18.0 || ^20.9.0 || >=21.1.0(#17725) (Milos Djermanovic)
特性
🌐 Features
8792464功能:启用 eslint.config.mjs 和 eslint.config.cjs (#17909) (Nicholas C. Zakas)24ce927功能:默认警告未使用的禁用指令 (#17879) (Bryan Mishkin)
错误修复
🌐 Bug Fixes
f182114修复:扁平配置中的深度合并行为 (#17906) (Francesco Trotta)b577e8a修复:允许配置中的循环引用 (#17752) (Francesco Trotta)
文档
🌐 Documentation
7f0ba51文档:在版本选择器中显示NEXT(#17911) (Milos Djermanovic)0a7911e文档:在 v9 迁移指南中添加平面配置默认值 (#17927) (Milos Djermanovic)94f8065文档:添加 CLI 更新以迁移到 v9 指南 (#17924) (Nicholas C. Zakas)16187f2文档:在迁移到 v9 指南中添加导出和字符串配置说明 (#17926) (Nicholas C. Zakas)3ae50cc文档:添加 RuleTester 更改以迁移到 v9 指南 (#17923) (Nicholas C. Zakas)0831b58文档:在 v9 迁移指南中添加规则更改 (#17925) (Milos Djermanovic)037abfc文档:更新 API 文档 (#17919) (Milos Djermanovic)afc3c03文档:在 v9 迁移指南中添加函数风格和meta.schema变更 (#17912) (Milos Djermanovic)1da0723文档:更新迁移到 v9.x 中的eslint:recommended部分 (#17908) (Milos Djermanovic)f55881f文档:移除 configuration-files-new (#17907) (Milos Djermanovic)63ae191文档:迁移到 v9.0.0 (#17905) (Nicholas C. Zakas)e708496文档:默认切换到扁平配置 (#17840) (Nicholas C. Zakas)fdf0424文档:更新为平面配置创建插件 (#17826) (Nicholas C. Zakas)e6a91bd文档:将可共享配置文档切换为使用扁平配置 (#17827) (Nicholas C. Zakas)3831fb7文档:更新了max-lines规则的示例 (#17898) (Tanuj Kanti)cd1ac20文档:更新自述文件(GitHub Actions 机器人)
杂项
🌐 Chores
17fedc1事务:升级 @eslint/js@9.0.0-alpha.0 (#17928) (Milos Djermanovic)cb89ef3事务:更新 package.json 以适配 @eslint/js 版本发布(Jenkins)f6f4a45任务:为 v9 放弃 structuredClone polyfill (#17915) (Kevin Gibbons)412dcbb杂务:升级 eslint-plugin-n 至 16.6.0 (#17916) (Milos Djermanovic)02a8baf杂项:重命名带下划线的文件 (#17910) (Nicholas C. Zakas)c0f5d91任务:在测试中移除创建未使用的 Linter 实例 (#17902) (Milos Djermanovic)3826cdf事务:使用 jsdoc/no-multi-asterisks 并允许空格: true (#17900) (Percy Ma)a9a17b3杂项:修复测试中获取作用域的问题 (#17899) (Milos Djermanovic)595a1f6测试:确保 CLI 测试在 FlatESLint 下运行 (#17884) (Francesco Trotta)c7eca43杂务:将依赖 markdownlint-cli 更新到 ^0.38.0 (#17865) (renovate[bot])cc0c9f7ci: 将 github/codeql-action 从 2 升级到 3 (#17873) (dependabot[bot])
