ESLint v9.27.0 发布

我们刚刚发布了 ESLint v9.27.0,这是 ESLint 的一次小版本升级。此版本添加了一些新功能,并修复了上一版本中发现的几个错误。

亮点

🌐 Highlights

MCP 服务器的独立包

🌐 Separate Package for MCP Server

ESLint MCP 服务器在 v9.26.0 中被添加到核心,现在已被提取到一个独立的包 @eslint/mcp。可以通过运行 npx @eslint/mcp@latest 来启动该服务器。有关设置和使用的更多详细信息,请阅读 文档

🌐 The ESLint MCP server, added to the core in v9.26.0, has been extracted into a separate package @eslint/mcp. The server can be started by running npx @eslint/mcp@latest. For more details on setup and usage, please read the documentation.

此更改旨在减少 ESLint 依赖的数量和大小。--mcp ESLint CLI 标志仍然有效,为已经依赖它的用户保持相同的行为,但现在它只是运行 npx @eslint/mcp@latest

🌐 This change has been made to reduce the number and size of ESLint dependencies. The --mcp ESLint CLI flag still works, maintaining the same behavior for users who are already relying on it, but now it just runs npx @eslint/mcp@latest.

ESLINT_FLAGS 环境变量

🌐 ESLINT_FLAGS environment variable

功能标记 现在也可以使用 ESLINT_FLAGS 环境变量进行设置。

# .bashrc

export ESLINT_FLAGS="unstable_config_lookup_from_file,unstable_native_nodejs_ts_config"

这种方法在 CI/CD 管道中尤其有用,或者当你想在多个 ESLint 命令中启用相同的标志时。

🌐 This approach can be especially useful in CI/CD pipelines or when you want to enable the same flags across multiple ESLint commands.

有关更多详细信息,请参阅 使用环境变量启用功能标志

🌐 See Enable Feature Flags with Environment Variables for more details.

已排序 eslint-suppressions.json

🌐 Sorted eslint-suppressions.json

抑制文件 中的对象键现在已排序,以避免内容更改时产生不必要的差异。

🌐 Object keys in suppressions files are now sorted, to avoid unnecessary diff when the content changes.

新规则 no-unassigned-vars

🌐 New Rule no-unassigned-vars

核心中已添加了一条新规则:no-unassigned-vars

🌐 One new rule has been added to the core: no-unassigned-vars.

此规则报告使用 letvar 声明但从未赋值却仍在代码中读取的变量。由于这些变量的值将始终为 undefined,它们的使用可能是编程错误。

🌐 This rule reports variables declared using let or var that are never assigned a value but are still read in the code. Since these variables will always have the value undefined, their usage is likely a programming mistake.

/*eslint no-unassigned-vars: "error"*/

let status; // error: 'status' is always 'undefined' because it's never assigned.

if (status === 'ready') {
  console.log('Ready!');
}

no-useless-escape 中的 allowRegexCharacters 选项

🌐 allowRegexCharacters option in no-useless-escape

no-useless-escape 规则有一个新的 allowRegexCharacters 选项,它可用于允许在正则表达式字面量中对指定字符进行不必要的转义。

🌐 The no-useless-escape rule has a new allowRegexCharacters option, which can be used to allow unnecessary escapes for specified characters in regular expression literals.

/*eslint no-useless-escape: ["error", { "allowRegexCharacters": ["-"] }]*/

/[0\-]/; // not reported, because "-" is specified in "allowRegexCharacters"

在上述示例中,转义 - 并不会改变正则表达式的行为,因此默认情况下,此规则会报告它。然而,允许转义 - 可能是有用的,以防止它在字符类末尾添加另一个字符时形成范围语法。

🌐 In the above example, escaping - doesn’t change the behavior of the regular expression, and therefore this rule would report it by default. However, allowing escaped - might be useful to prevent it from forming the range syntax if another character is later added to the end of the character class.

no-array-constructor可以自动修复

🌐 no-array-constructor is autofixable

no-array-constructor 规则报告的大多数问题现在可以通过 --fix 命令行选项自动修复。

🌐 Most problems reported by the no-array-constructor rule can now be automatically fixed with the --fix command line option.

在修复不安全的情况下,例如由于未知数量的参数而导致的 new Array(...args),以及在传递单个参数时 Array 构造函数的特定行为,此规则仍然提供建议。

🌐 In cases where the fix wouldn’t be safe, such as new Array(...args) due to an unknown number of arguments and the specific behavior of the Array constructor when a single argument is passed, this rule still provides suggestions.

核心规则中的 TypeScript 语法支持

🌐 TypeScript Syntax Support in Core Rules

正如在 ESLint v9.23.0 发布博客文章 中宣布的那样,我们正在积极努力将 TypeScript 语法支持添加到核心规则中。

🌐 As announced in the ESLint v9.23.0 release blog post, we are actively working to add TypeScript syntax support to core rules.

ESLint v9.27.0 为另外两个核心规则引入了完整的 TypeScript 语法支持。这些规则是:

🌐 ESLint v9.27.0 introduces full TypeScript syntax support for two more core rules. These rules are:

  • max-params。这个规则有一个新的 TypeScript 特定选项 countVoidThis
  • no-unassigned-vars。这个新增加的规则从一开始就支持 TypeScript 语法,不会报告全局声明。

这些规则现在可以用于检查 TypeScript 文件以及常规 JavaScript 文件。 要检查 TypeScript 代码,请确保使用 @typescript-eslint/parser 或其他兼容的解析器。

🌐 These rules can now be used to lint TypeScript files as well as regular JavaScript. To lint TypeScript code, be sure to use @typescript-eslint/parser, or another compatible parser.

特性

🌐 Features

错误修复

🌐 Bug Fixes

  • 5687ce7 修复:纠正不匹配的已删除规则 (#19734) (루밀LuMir)
  • dc5ed33 修复:纠正类型并在 SourceCode 类中收紧类型定义 (#19731) (루밀LuMir)
  • de1b5de 修复:纠正 Linter.ESLintParseResult 类型中的 service 属性名 (#19713) (Francesco Trotta)
  • 60c3e2c 修复:对 eslint-suppressions.json 中的键进行排序以避免 git 频繁变动 (#19711) (Ron Waldon-Howe)
  • 9da90ca 修复:将 allowReserved 添加到 Linter.ParserOptions 类型 (#19710) (Francesco Trotta)
  • fbb8be9 修复:将 info 添加到 ESLint.DeprecatedRuleUse 类型 (#19701) (Francesco Trotta)

文档

🌐 Documentation

  • 25de550 文档:更新冻结规则的描述以提及 TypeScript (#19736) (Nicholas C. Zakas)
  • bd5def6 文档:清理配置文件文档 (#19735) (Nicholas C. Zakas)
  • 4d0c60d 文档:将 Neovim 添加到编辑器集成中 (#19729) (Maria José Solano)
  • 71317eb 文档:更新自述文件(GitHub Actions 机器人)
  • 4c289e6 文档:更新自述文件(GitHub Actions 机器人)
  • f0f0d46 文档:澄清未使用的抑制会导致非零退出代码 (#19698) (Milos Djermanovic)
  • 8ed3273 文档:修复 ConfigData 类型的内部使用 (#19688) (Francesco Trotta)
  • eb316a8 文档:在 Package.json Conventions 中添加 fmtcheck 部分 (#19686) (루밀LuMir)
  • a3a2559 文档:修复 Combine Configs 中的措辞 (#19685) (Milos Djermanovic)
  • c8d17e1 文档:更新自述文件(GitHub Actions 机器人)

杂项

🌐 Chores

  • f8f1560 杂务:升级 @eslint/js@9.27.0 (#19739) (Milos Djermanovic)
  • ecaef73 事务:更新 package.json 以适配 @eslint/js 版本发布(Jenkins)
  • 596fdc6 事务:将依赖 @arethetypeswrong/cli 更新到 ^0.18.0 (#19732) (renovate[bot])
  • f791da0 杂项:从 .editorconfig 中移除不平衡的大括号 (#19730) (Maria José Solano)
  • e86edee 重构:整合配置助手 (#19675) (Nicholas C. Zakas)
  • cf36352 杂务:移除共享类型 (#19718) (Francesco Trotta)
  • f60f276 重构:更容易创建 RuleContext (#19709) (Nicholas C. Zakas)
  • 58a171e 任务:将依赖 @eslint/plugin-kit 更新到 ^0.3.1 (#19712) (renovate[bot])
  • 3a075a2 杂项:将依赖 @eslint/core 更新到 ^0.14.0 (#19715) (renovate[bot])
  • 44bac9d ci:在 Node.js 24 中运行测试 (#19702) (Francesco Trotta)
  • 35304dd 事务:向包中添加缺失的 funding 字段 (#19684) (루밀LuMir)
  • f305beb 测试:模拟 process.emitWarning 以防止输出中断 (#19687) (Francesco Trotta)

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