ESLint v9.0.0-alpha.0 发布

我们刚刚发布了 ESLint v9.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 < 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.mjseslint.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.

移除了除 stylishhtmljsonjson-with-meta 外的所有格式化器

🌐 Removed all formatters except stylish, html, json, and json-with-meta

以下格式化工具已被移除:

🌐 The following formatters have been removed:

  • checkstyle
  • compact
  • jslint-xml
  • junit
  • tap
  • unix
  • visualstudio

如果你当前正在使用这些格式化工具,则需要安装 独立包 以用于 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-jsdocrequire-jsdoc 规则

🌐 Removed valid-jsdoc and require-jsdoc rules

我们已移除 valid-jsdocrequire-jsdoc。我们建议改用 eslint-plugin-jsdoc 插件。

🌐 We have removed valid-jsdoc and require-jsdoc. We recommend using the eslint-plugin-jsdoc plugin instead.

移除了 contextSourceCode 上的不推荐使用的方法

🌐 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:

  1. 函数风格的规则将在 v9.0.0 中停止工作。函数风格的规则是通过从文件中导出一个函数而不是导出带有 create() 方法的对象来创建的规则。
  2. 当规则没有指定 meta.schema 时,将应用默认架构 []。这意味着没有架构的规则将被假定为没有选项,这反过来意味着如果提供了选项,验证将失败。
  3. 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)
  • cadfbcd feat!: 将 FlatESLint 重命名为 ESLint (#17914) (Nicholas C. Zakas)
  • d1018fc 功能更新!: 在 --quiet 模式下跳过运行警告 (#17274) (Maddy Miller)
  • fb81b1c feat!: 设置默认 schema: [],放弃对函数风格规则的支持 (#17792) (Milos Djermanovic)
  • 0b21e1f 功能更新!: 为 no-implicit-coercion 添加两个更多用例 (#17832) (Gürgün Dayıoğlu)
  • 2916c63 feat!: 默认将 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)
  • 8fe8c56 feat!: 更新 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 ✨)
  • e563c52 feat!: 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])
  • cc0c9f7 ci: 将 github/codeql-action 从 2 升级到 3 (#17873) (dependabot[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 的一次小版本升级。此版本添加了一些新功能,并修复了上一版本中发现的几个错误。