ESLint v9.29.0 发布

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

亮点

🌐 Highlights

ECMAScript 2026 显式资源管理

🌐 ECMAScript 2026 Explicit Resource Management

ESLint 的默认解析器 espree 现在支持新的 显式资源管理 语法:usingawait 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 全局变量 Float16ArrayIterator 将自动启用。
  • --prune-suppressions CLI 选项现在也会删除不再存在的文件条目。
  • includeIgnoreFile() 辅助函数现在接受第二个可选的 name 参数,它允许你为该函数返回的配置对象设置自定义名称。
  • class-methods-use-this 规则现在支持类自动存取器。这个语言特性是 装饰器 提案的一部分,该提案仍处于第 3 阶段,但自动存取器语法已经可以在 TypeScript 中使用。

特性

🌐 Features

错误修复

🌐 Bug Fixes

文档

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

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