ESLint v9.24.0 发布

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

亮点

🌐 Highlights

批量抑制

🌐 Bulk Suppressions

此版本引入了批量抑制功能。此功能允许在不立即修复所有违规的情况下,将新的 lint 规则启用为 "error"。虽然该规则会在新代码中强制执行,但现有违规将不会被报告。这样,你可以根据自己的节奏处理现有违规。

🌐 This release introduces the bulk suppressions feature. This feature allows for enabling new lint rules as "error" without fixing all violations upfront. While the rule will be enforced for new code, the existing violations will not be reported. This way, you can address the existing violations at your own pace.

# Fix all autofixable violations and suppress the remaining ones
eslint --suppress-all --fix

# Fix all autofixable violations, but suppress only violations for <rule-name>
eslint --suppress-rule <rule-name> --fix

这种方法优先阻止新的违规行为,同时提供了一个清晰的路径来逐步改进现有代码。

🌐 This approach prioritizes preventing new violations while providing a clear path to incrementally improve existing code.

你可以在公告博客文章批量屏蔽文档页面中找到所有详细信息。

🌐 You can find all the details in the announcement blog post and the Bulk Supressions documentation page.

./ 开头的模式

🌐 Patterns starting with ./

在 ESLint v9.24.0 之前,以 ./ 开头的 filesignores 模式会被忽略。

🌐 Prior to ESLint v9.24.0, files and ignores patterns that start with ./ were ignored.

截至 ESLint v9.24.0,这些模式被视为相对于配置基路径(配置文件的位置,或者如果使用了 --config 命令行选项,则为当前工作目录)。以 ./ 开头的模式等同于没有 ./ 前缀的相同模式。

🌐 As of ESLint v9.24.0, these patterns are treated as relative to the config base path (the location of the config file, or the current working directory if the --config command line option was used). A pattern that starts with ./ is equivalent to the same pattern without the ./ prefix.

// eslint.config.js
export default [

    {
        // Equivalent to `ignores: ["foo.js"]`
        ignores: ["./foo.js"]
    },

    {
        // Equivalent to `files: ["bar/*.js"]`
        files: ["./bar/*.js"],

        rules: {
            "no-undef": "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.24.0 为另外四个核心规则引入了完整的 TypeScript 语法支持。这些规则是:

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

这些规则现在可以用于检查 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.

此外,class-methods-use-this 规则有两个新的 TypeScript 特定选项:ignoreOverrideMethodsignoreClassesWithImplements

🌐 Additionally, the class-methods-use-this rule has two new TypeScript-specific options: ignoreOverrideMethods and ignoreClassesWithImplements.

Node.js 原生加载 TypeScript 配置文件(实验性功能)

🌐 Node.js Native Loading of TypeScript Configuration Files (Experimental)

如果你使用的是 Node.js >= 22.10.0,你现在可以在不安装 jiti 的情况下使用 TypeScript 配置文件eslint.config.tseslint.config.mtseslint.config.cts)。这要归功于 --experimental-strip-types Node.js 标志。

🌐 If you’re using Node.js >= 22.10.0, you can now use TypeScript configuration files (eslint.config.ts, eslint.config.mts, or eslint.config.cts) without installing jiti. This is possible thanks to the --experimental-strip-types Node.js flag.

由于此功能仍在实验阶段,你还必须启用 unstable_native_nodejs_ts_config ESLint 标志。

🌐 Since this feature is still experimental, you must also enable the unstable_native_nodejs_ts_config ESLint flag.

npx --node-options='--experimental-strip-types' eslint --flag unstable_native_nodejs_ts_config

特性

🌐 Features

错误修复

🌐 Bug Fixes

文档

🌐 Documentation

  • f857820 文档:更新 --experimental-strip-types 的文档 (#19594) (Nikolas Schröter)
  • 803e4af 文档:简化 includeIgnoreFile 部分的 gitignore 路径处理 (#19596) (Thomas Broyer)
  • 6d979cc 文档:更新自述文件(GitHub Actions 机器人)
  • 82177e4 文档:更新自述文件(GitHub Actions 机器人)
  • e849dc0 文档:用 const 替换现有的 var (#19578) (Sweta Tanwar)
  • 0c65c62 文档:在 lint 规则示例中不要传递文件名 (#19571) (Milos Djermanovic)
  • 6be36c9 文档:更新 fixer 的自定义规则代码示例 (#19555) (潘一帆)

构建相关

🌐 Build Related

  • 366e369 构建:为 package.json 文件重新启用 Prettier 格式化 (#19569) (Francesco Trotta)

杂项

🌐 Chores

  • ef67420 杂务:升级 @eslint/js@9.24.0 (#19602) (Milos Djermanovic)
  • 4946847 事务:更新 package.json 以适配 @eslint/js 版本发布(Jenkins)
  • a995acb 杂务:纠正包脚本中的 ‘flter’/‘filter’ 拼写错误 (#19587) (Josh Goldberg ✨)
  • b9a5efa 测试:在 Windows 上跳过符号链接测试 (#19503) (fisker Cheung)
  • 46eea6d 任务:从 shared/types.js 中移除 RuleFormatterFunction (#19556) (Nitin Kumar)
  • bdcc91d 杂项:修改 .editorconfig 以与 prettier 配置保持一致 (#19577) (Sweta Tanwar)
  • 7790d83 杂务:修复评论中的一些拼写错误 (#19576) (todaymoon)
  • 76064a6 测试:忽略 package-lock.jsoneslint-webpack-plugin 的影响 (#19572) (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 的一次小版本升级。此版本添加了一些新功能,并修复了上一版本中发现的几个错误。