ESLint v9.0.0-alpha.1 发布

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

亮点

🌐 Highlights

这是本版本 ESLint 中你需要了解的主要更改的总结。

🌐 This is a summary of the major changes you need to know about for this version of ESLint.

正在安装

🌐 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.1 --save-dev

迁移指南

🌐 Migration Guide

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

🌐 As there are a lot of changes, we’ve created a migration guide describing the 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.

no-inner-declarations 新的默认行为

🌐 no-inner-declarations new default behavior

在 v8.x 中,no-inner-declarations 会将块内定义的任何函数标记为错误,因为这种行为在早期版本的 JavaScript 中是未定义的。自 ES 2015 起,块级作用域函数声明已经被明确定义,因此我们将默认行为更改为不对块级作用域函数发出警告。

🌐 In v8.x, no-inner-declarations would flag any functions defined inside of blocks as errors because this behavior was undefined in early versions of JavaScript. As of ES 2015, block-scoped function declarations are well-defined and so we changed the default behavior to not warn on block-scoped functions.

no-misleading-character-class 现在高亮有问题的字符

🌐 no-misleading-character-class now highlights the offending characters

在 v8.x 中,no-misleading-character-class 规则如果正则表达式包含误导性的字符类,会高亮整个正则表达式。在 v9.0.0 中,该规则现在仅高亮有问题的字符,以帮助你更容易地找到错误。

🌐 In v8.x, the no-misleading-character-class rule would highlight an entire regular expression if it contained a misleading character class. In v9.0.0, this rule now highlights just the offending characters to help you more easily find errors.

no-unused-vars varsIgnorePattern 选项更改

🌐 no-unused-vars varsIgnorePattern option change

no-unused-varsvarsIgnorePattern 选项在 catch 条件中错误地应用于捕获的错误变量。在 v9.0.0 中,varsIgnorePattern 不再适用于捕获的错误变量。

🌐 The varsIgnorePattern option of no-unused-vars was incorrectly applied to caught error variables in catch conditions. In v9.0.0, varsIgnorePattern no longer applies to caught error variables.

新规则:no-useless-assignment

🌐 New rule: no-useless-assignment

ESLint v9.0.0 引入了一条新规则 no-useless-assignment,旨在发现你给变量赋值但该值从未被使用的情况。例如:

🌐 ESLint v9.0.0 introduces a new rule, no-useless-assignment, that is designed to catch situations where you’ve assigned a value to a variable and that value is never used. For example:

let id = 1234;      // 1234 is never used
id = calculateId();

--output-file 标志现在保证文件会被输出

🌐 The --output-file flag now guarantees a file is output

--output-file CLI 标志旨在将 ESLint 运行的结果输出到指定文件。在此版本之前,如果 lint 检查通过且没有错误或警告,将不会输出任何文件。在 v9.0.0 中,当 lint 检查通过且没有任何错误或警告时,将输出一个空文件。

🌐 The --output-file CLI flag is designed to output the results of the ESLint run to specified file. Prior to this release, no file would be output if linting passed with no errors or warnings. In v9.0.0, an empty file will be output when linting passes without any errors or warnings.

更好的范围分析

🌐 Better scope analysis

在 v9.0.0 中,我们更新了 eslint-scope 的行为以修复几个长期存在的漏洞:

🌐 In v9.0.0, we updated the behavior of eslint-scope to fix a couple of longstanding bugs:

  1. 之前,ESLint 会将 ("use strict") 视为严格模式指令,即使它不是。我们修复了该行为,现在只有有效的严格模式指令才会被认可。
  2. extends 条款的包含作用域被错误地设置为包含该类的作用域,而它本应是类本身的作用域。这已经被修复。

CodePath#currentSegments 已移除

🌐 CodePath#currentSegments removed

如我们在上一篇帖子中宣布的那样,CodePath#currentSegments 已从规则 API 中移除。更多详情请参阅该帖子。

🌐 As announced in our previous post, CodePath#currentSegments has been removed from the rules API. Please refer to the post for more details.

重大更改

🌐 Breaking Changes

  • 701f1af 功能更新!: no-inner-declaration 新的默认行为和选项 (#17885) (Tanuj Kanti)
  • bde5105 修复!: 处理保存到磁盘时 --output-file 的空输出 (#17957) (Nitin Kumar)
  • 07107a5 修复!: 升级 eslint-scope@8.0.0 (#17942) (Milos Djermanovic)
  • 3ee0f6c 修复!: no-unused-vars varsIgnorePattern 在 catch 参数中的行为 (#17932) (Tanuj Kanti)
  • 51f8bc8 修复!: 仅带严重性的配置注释应保留选项 (#17945) (Milos Djermanovic)
  • d191bdd 功能更新!: 移除 CodePath#currentSegments (#17936) (Milos Djermanovic)

特性

🌐 Features

错误修复

🌐 Bug Fixes

文档

🌐 Documentation

  • 96307da 文档:no-inner-declarations 的迁移指南条目 (#17977) (Tanuj Kanti)
  • 40be60e 文档:更新自述文件(GitHub Actions 机器人)
  • d31c180 文档:修复自定义规则页面上的代码路径事件数量 (#17969) (Richard Hunter)
  • 1529ab2 文档:在 v9 迁移指南中重新排序条目 (#17967) (Milos Djermanovic)
  • 9507525 文档:解释如何合并配置 (#17947) (Nicholas C. Zakas)
  • 7c78576 文档:添加更多已移除的 context 方法以迁移到 v9 指南 (#17951) (Milos Djermanovic)
  • 3a877d6 文档:更新已移除的 CLI 标志迁移 (#17939) (Nicholas C. Zakas)
  • 4a9cd1e 文档:更新 v9 的 Linter API (#17937) (Milos Djermanovic)
  • 2a8eea8 文档:更新 v9.0.0-alpha.0 的文档 (#17929) (Milos Djermanovic)

构建相关

🌐 Build Related

  • c2bf27d 构建:在发布预发布版本时更新文档文件 (#17940) (Milos Djermanovic)

杂项

🌐 Chores

  • c5e50ee 事务:更新 package.json 以适配 @eslint/js 版本发布(Jenkins)
  • 1bf2520 事务: 将文档 CI 与核心 CI 分离 (#17897) (Nicholas C. Zakas)
  • 320787e 任务: 删除 relative-module-resolver.js (#17981) (Francesco Trotta)
  • 4926f33 重构:使用 Object.hasOwn() (#17948) (Milos Djermanovic)
  • df200e1 重构:使用 Array.prototype.at() 获取最后的元素 (#17949) (Milos Djermanovic)
  • 750b8df 事务: 将依赖 glob 更新到 v10 (#17917) (renovate[bot])
  • 74794f5 事务: 移除了未使用的 eslintrc 模块 (#17938) (Milos Djermanovic)
  • 10ed29c 杂务:移除未使用的依赖 rimraf (#17934) (Francesco Trotta)
  • 903ee60 ci:安装 eslint 时使用 --force 标志 (#17921) (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 的一次小版本升级。此版本添加了一些新功能,并修复了上一版本中发现的几个错误。