多文件分析
🌐 Multi-file analysis
多文件分析允许规则使用整个项目的信息,例如模块依赖图,而不是孤立地分析每个文件。
🌐 Multi-file analysis allows rules to use project-wide information, such as the module dependency graph, instead of analyzing each file in isolation.
性能与架构
🌐 Performance and architecture
ESLint 是为每个文件评估规则,不提供内置的项目图。插件如 ['eslint-plugin-import'](https://github.com/import-js/eslint-plugin-import)必须重建模块分辨率和ESLint核心外的模块图。项目报告原始的“import/no-cycle”规则需要几十秒,或者在较大的仓库中超过一分钟。
🌐 ESLint evaluates rules per file and does not provide a built-in project graph. Plugins such as eslint-plugin-import must rebuild module resolution and the module graph outside of ESLint’s core. Projects report the original import/no-cycle rule taking tens of seconds, or - on larger repositories - over a minute.
Oxlint 在核心引擎中实现了多文件分析。它可以对文件进行代码检查并并行构建模块图,在规则之间共享解析和解析结果,通常能在几秒钟内完成类似的 import/no-cycle 检查。
🌐 Oxlint implements multi-file analysis in the core engine. It lints files and builds the module graph in parallel, shares parsing and resolution across rules, and typically completes comparable import/no-cycle checks in a few seconds.
启用 import 插件
🌐 Enable the import plugin
要使用多文件分析,你必须启用 import 插件并至少配置一条 import/* 规则。示例请参见下一节的配置文件。
🌐 To use multi-file analysis, you must enable the import plugin and configure at least one import/* rule. For an example, see the config file in the next section.
使用 import/no-cycle 检测循环
🌐 Detect cycles with import/no-cycle
启用 import/no-cycle 以检测循环依赖。
🌐 Enable import/no-cycle to detect circular dependencies.
导入周期:
🌐 Import cycles:
- 不明确的依赖方向
- 使重构更困难
- 可能由于求值顺序而导致导入的值为
undefined
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["import"],
"rules": {
"import/no-cycle": ["error", { "maxDepth": 3 }]
}
}TypeScript 路径别名
🌐 TypeScript path aliases
在运行 import/* 规则时,Oxlint 会自动发现 tsconfig.json 来解析 TypeScript 路径别名,例如 compilerOptions.paths。
🌐 When running import/* rules, Oxlint automatically discovers tsconfig.json to resolve TypeScript path aliases such as compilerOptions.paths.
