
亮点
🌐 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.
此版本的大部分亮点都是重大更改,并在迁移指南中有更详细的讨论。下面是重大更改的摘要。(不太重要的更改包含在迁移指南中。)
🌐 Most of the highlights of this release are breaking changes, and are discussed further in the migration guide. There are summaries of the significant changes below. (Less significant changes are included in the migration guide.)
此 ESLint 预发布版本有一个单独的文档部分。
🌐 This prerelease version of ESLint has a separate documentation section.
RuleTester 断言选项
🌐 RuleTester assertion options
RuleTester#run() 方法现在支持 断言选项,具体包括 requireMessage 和 requireLocation,以便开发者在规则测试中强制执行更严格的要求。这些选项确保每个无效的测试用例都明确检查违规消息和/或位置,从而保证如果不符合要求,测试将会失败。
🌐 The RuleTester#run() method now supports assertion options, specifically requireMessage and requireLocation, to let developers enforce stricter requirements in rule tests. These options enforce that every invalid test case explicitly checks violation messages and/or locations, ensuring that a test fails if it doesn’t meet the requirements.
requireMessage- 确保每个测试用例都包含消息检查。
- 接受:
true:必须使用对象数组作为errors,而不是数字计数简写,以检查规则报告的问题。每个对象必须像往常一样包含message或messageId属性,以检查报告问题的消息。"message":必须仅使用message进行检查。"messageId":必须仅使用messageId进行检查。
- 目的: 防止测试在未验证实际消息的情况下通过。
requireLocation- 确保每个测试用例都包括位置检查。
- 接受:
true - 在
errors数组的每个对象中需要line和column。 endLine和endColumn是可选的,如果实际报告中不包括它们。- 目的: 保证测试能够验证错误的位置。
示例用法:
ruleTester.run("my-rule", rule, {
valid: [
{ code: "var foo = true;" }
],
invalid: [
{
code: "var invalidVariable = true;",
errors: [
{ message: "Unexpected invalid variable.", line: 1, column: 5 }
]
}
],
assertionOptions: {
requireMessage: true,
requireLocation: true
}
});
在这里,测试必须针对每个错误包括消息检查和位置检查。
🌐 Here, the test must include both a message check and location check for each error.
JSX 引用现在已被跟踪
🌐 JSX references are now tracked
ESLint v10.0.0 现在跟踪 JSX 引用,从而能够正确分析 JSX 元素的作用域。
🌐 ESLint v10.0.0 now tracks JSX references, enabling correct scope analysis of JSX elements.
以前,JSX 标识符不会被追踪为引用,这可能导致依赖作用域信息的规则产生不正确的结果。例如:
🌐 Previously, JSX identifiers weren’t tracked as references, which could lead to incorrect results in rules relying on scope information. For example:
import { Card } from "./card.jsx";
export function createCard(name) {
return <Card name={name} />;
}
在 v10.0.0 之前:
🌐 Prior to v10.0.0:
- 误报:
<Card>可能会被报告为“已定义但从未使用” (no-unused-vars)。 - 假阴性:移除导入可能不会触发“未定义变量”错误 (
no-undef)。
从 v10.0.0 开始,<Card> 被视为对作用域内变量的普通引用。这消除了令人困惑的误报/漏报,使 JSX 处理符合开发者的预期,并改善了使用 JSX 的项目中的代码检查体验。
🌐 Starting with v10.0.0, <Card> is treated as a normal reference to the variable in scope. This eliminates confusing false positives/negatives, aligns JSX handling with developer expectations, and improves the linting experience in projects using JSX.
如果你的代码库包含 JSX,你可能会开始看到新的 lint 报告。要解决这些问题,请根据需要更新你的代码或调整规则配置。
🌐 If your codebase includes JSX, you may start seeing new linting reports. To fix them, update your code or adjust rule configurations as needed.
格式化器上下文中的 color 属性
🌐 color property in formatter context
当在命令行上指定 --color 或 --no-color 选项时,ESLint 会在传递给格式化器的上下文对象(format() 方法的第二个参数)上设置一个额外的 color 属性。对于 --color,该属性为 true;对于 --no-color,该属性为 false。自定义格式化器 可以使用该值来确定是否应用颜色样式,假设终端支持或不支持颜色,如该选项所示。
🌐 When the --color or --no-color option is specified on the command line, ESLint sets an additional color property on the context object passed to a formatter (the second argument of the format() method). This property is true for --color and false for --no-color. Custom formatters can use this value to determine whether to apply color styling, based on the assumption that the terminal supports or does not support colors as indicated by the option.
对于默认的“时尚”格式化程序,当决定是否应用颜色时,--color 或 --no-color 选项现在优先于 Node.js 检查的其他规则(例如环境变量 FORCE_COLOR、NODE_DISABLE_COLORS 等)。
🌐 For the default “stylish” formatter, the --color or --no-color option now takes precedence over other rules checked by Node.js (such as the environment variables FORCE_COLOR, NODE_DISABLE_COLORS, etc.) when deciding whether to apply colorization.
正在安装
🌐 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-beta.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
a176319功能更新!: 将chalk替换为styleText并将color添加到ResultsMeta(#20227) (루밀LuMir)c7046e6功能更新!: 启用 JSX 引用跟踪 (#20152) (Pixel998)
特性
🌐 Features
错误修复
🌐 Bug Fixes
ba6ebfa修复:纠正loadESLint()和shouldUseFlatConfig()的类型定义 (#20393) (루밀LuMir)e7673ae修复:纠正 RuleTester 类型定义 (#20105) (Pixel998)53e9522修复:已删除格式化检查的 strict (#20241) (ntnyq)b017f09修复:纠正no-restricted-import消息 (#20374) (Francesco Trotta)
文档
🌐 Documentation
264b981文档:更新自述文件(GitHub Actions 机器人)5a4324f文档:澄清no-unused-vars的"local"选项 (#20385) (Milos Djermanovic)e593aa0文档:提高文档网站 README 的清晰度、语法和措辞 (#20370) (Aditya)3f5062e文档:在规则元数据文档中添加 messages 属性 (#20361) (Sabya Sachi)9e5a5c2文档:从规则文档中删除Examples标题 (#20364) (Milos Djermanovic)194f488文档:更新自述文件(GitHub Actions 机器人)
构建相关
🌐 Build Related
杂项
🌐 Chores
