嵌套配置文件
🌐 Nested configuration files
Oxlint 可以在同一个仓库中使用多个配置文件。它会自动检测名为 .oxlintrc.json 的配置文件,并根据文件在目录树中的位置应用这些配置。
🌐 Oxlint can use multiple configuration files in the same repository. It automatically detects configuration files named .oxlintrc.json and applies them based on where files live in the directory tree.
这在需要各自设置的单一仓库中很有用,同时还能保持共享的基础配置。
🌐 This is useful in monorepos where packages need their own settings, while still keeping a shared baseline.
如果你只需要排除文件或文件夹,请改用 忽略。
🌐 If you only need to exclude files or folders, use Ignores instead.
它是如何工作的
🌐 How it works
对于每个正在进行 lint 的文件,Oxlint 会使用与该文件最近的 .oxlintrc.json。
🌐 For each file being linted, Oxlint uses the nearest .oxlintrc.json relative to that file.
给定以下结构:
🌐 Given the following structure:
my-project/
├── .oxlintrc.json
├── src/
│ ├── index.js
├── package1/
│ ├── .oxlintrc.json
│ └── index.js
└── package2/
├── .oxlintrc.json
└── index.js配置解析的工作方式如下:
🌐 Configuration resolution works as follows:
src/index.js使用my-project/.oxlintrc.jsonpackage1/index.js使用my-project/package1/.oxlintrc.jsonpackage2/index.js使用my-project/package2/.oxlintrc.json
期待什么
🌐 What to expect
配置文件不会自动合并。子目录中的配置不会影响父目录的配置。
🌐 Configuration files are not automatically merged. A config in a child directory does not affect the parent config.
命令行选项会覆盖配置文件,无论它们来自父目录还是子目录。
🌐 Command line options override configuration files, regardless of whether they come from a parent or child directory.
使用 -c 或 --config 传递显式配置文件位置会禁用嵌套配置查找,Oxlint 将只使用该单一配置文件。
🌐 Passing an explicit config file location using -c or --config disables nested config lookup, and Oxlint will only use that single configuration file.
你也可以使用 --disable-nested-configs 标志来禁用嵌套配置。
🌐 You can also disable nested configs with the --disable-nested-configs flag.
单体仓库模式:共享一个带有扩展的基础配置
🌐 Monorepo pattern: share a base config with extends
在单仓库中,你通常希望根节点有一个共享基线,并针对特定软件包进行小范围调整。
🌐 In a monorepo, you often want one shared baseline at the root, and small package specific adjustments.
你可以通过保留一个根 .oxlintrc.json,然后让包配置继承它来实现这一点。
🌐 You do this by keeping a root .oxlintrc.json, then having package configs extend it.
{
"rules": {
"no-debugger": "error"
}
}{
"extends": ["../.oxlintrc.json"],
"rules": {
"no-console": "off"
}
}这将共享的基线集中在一个地方,并使包配置简洁且专注。
🌐 This keeps the shared baseline in one place and makes package configs small and focused.
扩展配置文件
🌐 Extending configuration files
配置可以使用 extends 从其他文件中重用设置。该值是一个文件路径数组,相对于声明它们的配置文件解析。
🌐 A config can reuse settings from other files using extends. The value is an array of file paths, resolved relative to the config file that declares them.
扩展文件可以有任意名称。它们不需要被命名为 .oxlintrc.json,只要它们是有效的 JSON 配置文件即可。
🌐 Extended files can have any name. They do not need to be named .oxlintrc.json, as long as they are valid JSON configuration files.
示例:
🌐 Example:
{
"plugins": ["typescript"],
"rules": {
"typescript/no-explicit-any": "error"
}
}{
"extends": ["oxlint-typescript.json"],
"rules": {
"no-unused-vars": "warn"
}
}只有一些属性可以扩展。支持的属性有:
🌐 Only some properties can be extended. The supported properties are:
rulespluginsoverrides
