
亮点
🌐 Highlights
此版本的 ESLint 尚未准备好用于生产环境,提供此版本是为了在发布最终版本之前收集社区的反馈。如果你遇到任何问题或有任何反馈,请通过在我们的 GitHub 仓库 创建问题告诉我们。
🌐 This version of ESLint is not ready for production use and is provided to gather feedback from the community before releasing the final version. Please let us know if you have any problems or feedback by creating issues on our GitHub repo.
请注意,这个 ESLint 的预发布版本有一个独立的文档部分。
🌐 Note that this prerelease version of ESLint has a separate documentation section.
RuleTester 的增强功能
🌐 Enhancements to RuleTester
自最早期以来,ESLint 就提供了 RuleTester API,帮助插件作者针对自定义测试案例和配置测试他们的规则。本次发布对 RuleTester 进行了若干增强,以执行更强健的测试定义并改进调试。
🌐 Since its earliest days, ESLint has provided the RuleTester API to help plugin authors test their rules against custom test cases and configurations. This release introduces several enhancements to RuleTester to enforce more robust test definitions and improve debugging.
requireData 断言选项
🌐 requireData assertion option
一个新的断言选项 requireData 现已可用。当设置为 true 时,RuleTester 将要求无效测试用例在 messageId 引用包含占位符的消息时包含一个 data 对象。这有助于确保测试与依赖占位符替换的规则消息保持一致。
🌐 A new assertion option, requireData, is now available. When set to true, RuleTester will require invalid test cases to include a data object whenever a messageId references a message with placeholders. This helps ensure that tests remain consistent with rule messages that rely on placeholder substitution.
例如,考虑一个假设规则 no-trivial-sum,它报告诸如 1 + 2 的表达式,并定义一个带有占位符的消息:
🌐 For example, consider a hypothetical rule no-trivial-sum that reports on expressions such as 1 + 2 and defines a message with placeholders:
trivialSum: "Trivial sum found. Replace {{actualExpression}} with {{sum}}."
如果一个无效的测试用例包括 messageId: "trivialSum" 但省略了 data:
🌐 If an invalid test case includes messageId: "trivialSum" but omits data:
assertionOptions: { requireData: true },
invalid: [
{
code: "const a = 1 + 2;",
errors: [{ messageId: "trivialSum" }],
},
],
RuleTester 现在将抛出一个断言错误,表明缺少 data 属性。
为了解决此问题,请在错误对象中包含占位符值:
🌐 To resolve this, include the placeholder values in the error object:
{
code: "const a = 1 + 2;",
errors: [
{
messageId: "trivialSum",
data: { actualExpression: "1 + 2", sum: 3 },
},
],
},
改进了失败测试的位置信息报告
🌐 Improved location reporting for failing tests
RuleTester 现在会在堆栈跟踪中添加信息,使你更容易在源代码中定位失败的测试用例。例如,如果 no-trivial-sum 规则未能对 1 + 2 报告错误,则上一节中的测试用例将失败,测试输出将包括如下堆栈跟踪行:
roughly at RuleTester.run.invalid[0] (/my-project/test/no-trivial-sum.js:10)
roughly at RuleTester.run.invalid (/my-project/test/no-trivial-sum.js:7)
第一行表示:
🌐 The first line indicates:
invalid[0]:invalid数组中失败测试用例的索引/my-project/test/no-trivial-sum.js:10:该测试用例定义的文件和行号。许多IDE终端,包括Visual Studio Code的终端,都能识别这种格式,并允许你直接点击跳转到相关行。
第二行指向整个 invalid 数组的起始位置。
🌐 The second line points to the start of the entire invalid array.
请注意,这些行号可能并不总是包含在内,这取决于你的测试是如何构建的。当行无法精确确定时,仍然可以使用失败的测试索引(例如 0)和打印的代码片段来定位测试用例。
🌐 Note that these line numbers may not always be included, depending on how your tests are structured. When the lines cannot be determined precisely, the failing test index (e.g., 0) and the printed code snippet are still available to locate the test case.
max-params 规则中的 countThis 选项
🌐 countThis option in max-params rule
max-params 规则现在支持新的 countThis 选项,该选项取代了已弃用的 countVoidThis。使用 countThis: "never" 设置时,该规则在计算 TypeScript 函数的参数数量时,将忽略函数参数列表中的任何 this 注解。例如:
🌐 The max-params rule now supports the new countThis option, which supersedes the deprecated countVoidThis. With the setting countThis: "never", the rule will now ignore any this annotation in a function’s argument list when counting the number of parameters in a TypeScript function. For example:
function doSomething(this: SomeType, first: string, second: number) {
// ...
}
将被视为一个只接受两个参数的函数。
🌐 will be considered a function taking only 2 parameters.
正在安装
🌐 Installing
由于这是预发布版本,npm 不会自动升级。安装时必须指定 next 标签:
🌐 Since this is a pre-release version, you will not automatically be upgraded by npm. You must specify the next tag when installing:
npm i eslint@next --save-dev
你也可以直接指定版本:
🌐 You can also specify the version directly:
npm i eslint@10.0.0-rc.0 --save-dev
迁移指南
🌐 Migration Guide
由于有很多变化,我们创建了一个 迁移指南,详细描述了重大更改以及你应该采取的应对步骤。我们预计大多数用户应该能够在不更改构建的情况下升级,但如果遇到问题,迁移指南应该是一个有用的资源。
🌐 As there are a lot of changes, we’ve created a migration guide describing the breaking changes in great detail along with the steps you should take to address them. We expect that most users should be able to upgrade without any build changes, but the migration guide should be a useful resource if you encounter problems.
重大更改
🌐 Breaking Changes
特性
🌐 Features
f0cafe5功能:规则测试器添加断言选项requireData(#20409) (fnx)f7ab693功能:输出 RuleTester 测试用例失败索引 (#19976) (ST-DDT)7cbcbf9功能:向max-params添加countThis选项 (#20236) (Gerkin)
错误修复
🌐 Bug Fixes
d186f8c修复:更新 eslint (#20427) (renovate[bot])2332262修复:错误位置不应修改 RuleTester 中的错误消息 (#20421) (Milos Djermanovic)ab99b21修复:确保将filename作为第三个参数传递给verifyAndFix()(#20405) (루밀LuMir)8a60f3b修复:从ParserOptions类型中移除ecmaVersion和sourceType(#20415) (Pixel998)eafd727修复:移除TDZ范围类型 (#20231) (jaymarvelz)39d1f51修复:更正Scope类型 (#20404) (sethamus)2bd0f13修复:更新verify和verifyAndFix类型 (#20384) (Francesco Trotta)
文档
🌐 Documentation
65ed0c9文档:更新自述文件(GitHub Actions 机器人)b0e4717文档: [no-await-in-loop] 扩展不适用性 (#20363) (Niklas Hambüchen)fca421f文档:更新自述文件(GitHub Actions 机器人)d925c54文档:更新no-lone-blocks中的配置语法 (#20413) (Pixel998)7d5c95f文档:从规则示例中删除多余的sourceType: "module"(#20412) (Pixel998)02e7e71文档:修复带有扩展名示例文件中的.mts通配符模式 (#20403) (Ali Essalihi)
杂项
🌐 Chores
b4b3127事务:更新 package.json 以适配 @eslint/js 版本发布(Jenkins)f658419重构:从 JS 语言中移除raw解析器选项 (#20416) (Pixel998)2c3efb7任务:从类型测试夹具中移除category(#20417) (Pixel998)36193fd任务:从格式化器测试夹具中移除category(#20418) (Pixel998)e8d203b事务: 在check-rule-examples中添加 JSX 语言标签验证 (#20414) (Pixel998)bc465a1任务:固定依赖 (#20397) (renovate[bot])703f0f5测试:在linter测试中替换已弃用的规则 (#20406) (루밀LuMir)ba71baa测试:在类型测试中启用strict模式 (#20398) (루밀LuMir)f9c4968重构:移除lib/linter/rules.js(#20399) (Francesco Trotta)6f1c48e事务: v9.39.2 版本更新 (Jenkins)
