
亮点
🌐 Highlights
ECMAScript 2026 显式资源管理
🌐 ECMAScript 2026 Explicit Resource Management
ESLint 的默认解析器 espree 现在支持新的 显式资源管理 语法:using 和 await using 声明,当资源超出作用域时会自动调用 dispose 方法。
🌐 ESLint’s default parser espree now supports new Explicit Resource Management syntax: using and await using declarations, which automatically calls a dispose method when a resource goes out of scope.
if (something) {
using someResource = getSomeResource();
// ... use `someResource`
} // dispose `someResource`
async function foo() {
if (something) {
await using someResource = getSomeResource();
// ... use `someResource`
} // await dispose `someResource`
}
要启用解析此语法,请将 languageOptions.ecmaVersion 设置为 2026 或 "latest"(默认)。
🌐 To enable parsing this syntax, set languageOptions.ecmaVersion to 2026 or "latest" (default).
请注意,核心规则尚未更新以支持此语法。
🌐 Please note that the core rules have not yet been updated to support this syntax.
no-restricted-properties 中的新 allowProperties 选项
🌐 New allowProperties option in no-restricted-properties
现在可以配置 no-restricted-properties 规则来限制对象上的所有属性,除了特定的属性。
🌐 The no-restricted-properties rule can now be configured to restrict all properties on an object except for specific ones.
/* eslint no-restricted-properties: [2, { "object": "config", "allowProperties": ["settings", "version"] }] */
config.settings = { theme: "dark" }; // ok
config.version = "1.0.0"; // ok
config.apiKey = "12345"; // error
config.timeout = 5000; // error
核心规则中的 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.29.0 为另外两个核心规则引入了完整的 TypeScript 语法支持。这些规则是:
🌐 ESLint v9.29.0 introduces full TypeScript syntax support for two more core rules. These rules are:
no-restricted-globals。此规则现在会忽略类型注解中的引用。no-var。此规则现在允许在全局类型声明中使用var。
这些规则现在可以用于检查 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.
新的 SourceCode#isGlobalReference(node) 方法
🌐 New SourceCode#isGlobalReference(node) method
[SourceCode](/docs/latest/extend/custom-rules#accessing-the-source-code) 类有一个新方法 isGlobalReference(node)。
🌐 The SourceCode class has a new method isGlobalReference(node).
如果传入的 Identifier 节点引用了通过 languageOptions.globals、/* global */ 注释或 ecmaVersion 配置的全局变量,而不是由本地绑定声明的,则返回 true。
🌐 It returns true if passed Identifier node references a global variable configured via languageOptions.globals, /* global */ comments, or ecmaVersion, and not declared by a local binding.
const myRule = {
meta: {
// ...
},
create(context) {
return {
Identifier(node) {
if (context.sourceCode.isGlobalReference(node)) {
// do something
}
},
};
},
};
其他显著变化
🌐 Other notable changes
- 当
languageOptions.ecmaVersion设置为2025(或更高)或"latest"时,新的 ECMAScript 2025 全局变量Float16Array和Iterator将自动启用。 --prune-suppressionsCLI 选项现在也会删除不再存在的文件条目。includeIgnoreFile()辅助函数现在接受第二个可选的name参数,它允许你为该函数返回的配置对象设置自定义名称。class-methods-use-this规则现在支持类自动存取器。这个语言特性是 装饰器 提案的一部分,该提案仍处于第 3 阶段,但自动存取器语法已经可以在 TypeScript 中使用。
特性
🌐 Features
f686fcb功能:添加ecmaVersion: 2026,解析using和await using(#19832) (Milos Djermanovic)19cdd22功能:修剪不存在文件的抑制 (#19825) (TKDev7)b3d720f功能:添加 ES2025 全局变量 (#19835) (fisker Cheung)677a283功能:为 class-methods-use-this 添加自动访问器字段支持 (#19789) (sethamus)dbba058功能:允许在no-var中进行全局类型声明 (#19714) (Remco Haszing)342bd29功能:在 no-restricted-globals 中忽略类型注解 (#19781) (sethamus)786bcd1功能:为 no-restricted-properties 添加 allowProperties 选项 (#19772) (sethamus)05b66d0功能:添加sourceCode.isGlobalReference(node)方法 (#19695) (Nitin Kumar)
错误修复
🌐 Bug Fixes
85c082c修复:带有取反模式和数组的显式匹配行为 (#19845) (Milos Djermanovic)9bda4a9修复:修复LintOptions.filterCodeBlock类型 (#19837) (ntnyq)7ab77a2修复:纠正 FlatConfig 类型的破坏性弃用 (#19826) (Logicer)1ba3318修复:将language和dialects添加到no-use-before-define(#19808) (Francesco Trotta)
文档
🌐 Documentation
00e3e6a文档:为includeIgnoreFile添加对自定义名称参数的支持 (#19795) (루밀LuMir)3aed075文档:更新自述文件(GitHub Actions 机器人)a2f888d文档:通过添加链接和修复拼写错误来增强文档 (#19761) (루밀LuMir)53c3235文档:更新以澄清提示使用 (#19748) (Jennifer Davis)
杂项
🌐 Chores
5c114c9杂务:升级 @eslint/js@9.29.0 (#19851) (Milos Djermanovic)acf2201事务:更新 package.json 以适配 @eslint/js 版本发布(Jenkins)a806994重构:从扁平配置功能中移除 eslintrc (#19833) (Nicholas C. Zakas)152ed51测试:在代码路径分析测试中切换到平面配置模式 (#19824) (Milos Djermanovic)b647239杂务:使用 Renovate 更快地更新第一方依赖 (#19822) (Nicholas C. Zakas)7abe42e重构:SafeEmitter -> SourceCodeVisitor (#19708) (Nicholas C. Zakas)e392895性能:改进getLocFromIndex的时间复杂度 (#19782) (루밀LuMir)0ed289c任务:移除意外提交的文件 (#19807) (Francesco Trotta)
