
亮点
🌐 Highlights
核心规则中的 TypeScript 语法支持
🌐 TypeScript Syntax Support in Core Rules
ESLint v9.23.0 为三条核心规则引入了完整的 TypeScript 语法支持。这些规则是:
🌐 ESLint v9.23.0 introduces full TypeScript syntax support for three 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.
You can define the parser and the rules in your config file like this:
import { defineConfig } from "eslint/config";
import tsParser from "@typescript-eslint/parser";
export default defineConfig([
{
files: ["**/*.ts"],
languageOptions: {
parser: tsParser,
},
rules: {
"class-methods-use-this": "error",
"default-param-last": "error",
"no-useless-constructor": "error",
},
},
]);
ESLint 正在积极努力将 TypeScript 语法支持添加到其他核心规则中。请期待更多更新。
🌐 ESLint is actively working to add TypeScript syntax support to other core rules. Expect more updates soon.
冲突的自动修复检测
🌐 Conflicting Autofix Detection
在使用 —fix 选项运行 ESLint 时,某些问题可以自动修复。然而,当两个规则对某个代码部分的修复方式有不同意见时,会发生什么?
🌐 When running ESLint with the —fix option, some problems can be fixed automatically. However, what happens when two rules have differing opinions on how a specific part of code should be fixed?
结果是一个固定的代码,它无法满足任一规则,并且根据你的配置仍然会包含问题。
🌐 The result is a fixed code that fails to satisfy either rule, and that will still contain problems based on your configuration.
例如,考虑这个配置:
🌐 For instance, consider this configuration:
import { defineConfig } from "eslint/config";
import stylistic from "@stylistic/eslint-plugin";
import stylisticJs from "@stylistic/eslint-plugin-js";
export default defineConfig([
{
plugins: {
"@stylistic": stylistic,
"@stylistic/js": stylisticJs,
},
rules: {
"@stylistic/semi": ["error", "never"],
"@stylistic/js/semi": ["error", "always"],
},
},
]);
在上述配置中,规则 @stylistic/semi 设置为不允许在语句末尾使用分号,而规则 @stylistic/js/semi 总是要求使用分号。显然,不可能以一种方式修复代码,使得一个语句同时符合这两个约束。
🌐 In the above configuration, the rule @stylistic/semi is set to never allow semicolons at the end of a statement, but the rule @stylistic/js/semi always requires them.
Obviously, it isn’t possible fix the code in a way that a statement fits both constraints.
在以前的 ESLint 版本中,文件中存在冲突修复的唯一迹象就是修复后的代码仍然包含可修复的错误。这让许多用户感到惊讶,因为这种行为的原因通常不清楚。
🌐 In previous ESLint versions, the only indications for conflicting fixes in a file was the fact that the fixed code would still contain fixable errors. This was surprising to many users, as the cause for the behavior was often unclear.
ESLint v9.23.0 会检测到当两个规则产生冲突的修复时,并发出警告:
🌐 ESLint v9.23.0 detects when two rules produce conflicting fixes and emits a warning:
ESLint循环修复警告:在修复 path/to/file 时检测到循环修复。很可能你的配置中存在冲突的规则。
我们还提供说明来修复配置。
🌐 We also provide instructions to fix the config.
自动查找带有 “flat/” 前缀的配置
🌐 Automatic Lookup for Configs with “flat/” Prefix
对于插件开发者,一个有趣的新功能是 ESLint 能够检测通过 extends 属性指定的旧版配置名称,并回退使用带有 “flat/” 前缀的类似名称的配置。 这简化了需要为 ESLint v9 和之前版本维护类似配置但又不能更改命名约定以保持向后兼容的插件的操作。 详情请参见 文档。
🌐 An interesting new feature for plugin developers is ESLint’s ability to detect a legacy config specified by its name with the extends property, and fall back to use a config with a similar name with the “flat/” prefix.
This simplifies things for plugins that need to maintain similar configs for ESLint v9 and for previous versions, and that cannot change their naming conventions for backwards compatibility.
See the documentation for further information.
特性
🌐 Features
557a0d2功能:在 no-useless-constructor 中支持 TypeScript 语法 (#19535) (Josh Goldberg ✨)8320241功能:在default-param-last中支持 TypeScript 语法 (#19431) (Josh Goldberg ✨)833c4a3功能:defineConfig() 支持 “flat/” 配置前缀 (#19533) (Nicholas C. Zakas)4a0df16功能:循环自动修复/冲突规则检测 (#19514) (Milos Djermanovic)be56a68功能:在class-methods-use-this中支持 TypeScript 语法 (#19498) (Josh Goldberg ✨)
错误修复
🌐 Bug Fixes
0e20aa7修复:将已弃用的RuleContext方法移动到子类型 (#19531) (Francesco Trotta)cc3bd00修复:在no-useless-assignment的 catch 块中使用的变量报告 (#19423) (Tanuj Kanti)d46ff83修复:no-dupe-keys与 proto setter 的误报 (#19508) (Milos Djermanovic)e732773修复:按下回车键时搜索结果的导航 (#19502) (Tanuj Kanti)f4e9c5f修复:允许RuleTester测试node_modules/内的文件 (#19499) (fisker Cheung)
文档
🌐 Documentation
5405939文档:在规则文档的 TypeScript 示例中显示红色下划线 (#19547) (Milos Djermanovic)48b53d6文档:在示例中将 var 替换为 const (#19539) (Nitin Kumar)c39d7db文档:更新自述文件(GitHub Actions 机器人)a4f8760文档:恢复意外更改 (#19542) (Francesco Trotta)280128f文档:添加复制按钮 (#19512) (xbinaryx)cd83eaa文档:在示例中将var替换为const(#19530) (Nitin Kumar)7ff0cde文档:更新自述文件(GitHub Actions 机器人)996cfb9文档:将 sass 迁移到模块系统 (#19518) (xbinaryx)17cb958文档:在规则示例中将var替换为let和const(#19515) (Tanuj Kanti)83e24f5文档:将 var 替换为 let 或 const (#19511) (Jenna Toff)a59d0c0文档:更新 defineConfig 文档 (#19505) (Nicholas C. Zakas)fe92927文档:require-unicode-regexp为i标志和\w添加说明 (#19510) (Chaemin-Lim)
构建相关
🌐 Build Related
杂项
🌐 Chores
0ac8ea4杂务:更新依赖以发布 v9.23.0 版本 (#19554) (Francesco Trotta)20591c4事务:更新 package.json 以适配 @eslint/js 版本发布(Jenkins)901344f杂项:将依赖 @eslint/json 更新到 ^0.11.0 (#19552) (renovate[bot])5228383杂项:修复 update-readme 格式 (#19544) (Milos Djermanovic)5439525事务: 在 Trunk 中格式化 JSON 文件 (#19541) (Francesco Trotta)75adc99事务: 在 Trunk 中启用 Prettier (#19354) (Josh Goldberg ✨)2395168杂务:通过 trunk fmt 为 Prettier 添加了 .git-blame-ignore-revs (#19538) (Josh Goldberg ✨)129882d事务:通过 trunk fmt 使用 Prettier 格式化文件 (#19355) (Josh Goldberg ✨)1738dbc任务:在主干中临时禁用 prettier (#19537) (Josh Goldberg ✨)dc854fd杂务: 更新依赖 shelljs 至 ^0.9.0 (#19524) (renovate[bot])5d57496杂务:修复一些评论 (#19525) (jimmycathy)9c5c6ee测试:修复断言失败 (#19500) (fisker Cheung)7a699a6杂务:内部移除与格式相关的 lint 规则 (#19473) (Josh Goldberg ✨)c99db89测试:用 Cypress 替换 WebdriverIO (#19465) (Pixel998)
