Skip to content

忽略文件

🌐 Ignore files

大型代码库包含不应进行代码检查的文件,例如构建输出、第三方代码、快照或生成的工件。Oxlint 提供了一个可预测的忽略模型,非常适合用于 monorepos 和持续集成环境。

🌐 Large repositories contain files that should not be linted, such as build output, vendored code, snapshots, or generated artifacts. Oxlint provides a predictable ignore model that works well in monorepos and CI.

[!提示] 强烈建议在 .oxlintrc.json 中使用 "ignorePatterns" 来忽略文件,而不是使用单独的忽略文件。这可以确保每个开发者在运行 oxlint 的所有工具和命令(尤其是 IDE/编辑器集成)中拥有相同的忽略设置。同时,它还能将配置集中到一个文件中。

默认忽略

🌐 Default ignores

Oxlint 会自动忽略:

🌐 Oxlint automatically ignores:

  • .git 目录
  • 文件名中包含 .min.-min._min. 的压缩文件
  • .gitignore 匹配的文件(全局 gitignore 文件不生效)

隐藏文件不会被自动忽略。

🌐 Hidden files are not automatically ignored.

ignorePatterns

推荐的方法是在 .oxlintrc.json 中使用 ignorePatterns 来定义忽略项。这可以让忽略项靠近它们所属的配置,并且能自然地与嵌套配置配合使用。

🌐 The recommended approach is to define ignores in .oxlintrc.json using ignorePatterns. This keeps ignores close to the configuration they belong to and works naturally with nested configs.

模式是相对于配置文件解析的。

🌐 Patterns are resolved relative to the configuration file.

.oxlintrc.json
json
{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
  "ignorePatterns": ["dist/**", "coverage/**", "vendor/**", "test/snapshots/**"]
}

在 monorepo 中,嵌套配置可以忽略包特定的输出而不影响仓库的其他部分。

🌐 In monorepos, nested configs can ignore package specific output without affecting the rest of the repository.

.eslintignore

Oxlint 还支持 .eslintignore,以兼容现有的 ESLint 配置。在迁移过程中,现有的 .eslintignore 文件可以保留不动。语法与 .gitignore 兼容,包括注释和否定模式。

🌐 Oxlint also supports .eslintignore for compatibility with existing ESLint setups. Existing .eslintignore files can remain in place during migration. The syntax is compatible with .gitignore, including comments and negation patterns.

新项目在 .oxlintrc.json 中应优先使用 "ignorePatterns",并且我们强烈建议在迁移后尽快切换到 "ignorePatterns",如果不是在迁移过程中就切换的话。

🌐 New projects should prefer "ignorePatterns" in .oxlintrc.json, and we strongly recommend moving over to "ignorePatterns" soon after migrating, if not during migration.

从命令行忽略

🌐 Ignore from the command line

CLI 标志对于在 CI 或本地调试中进行一次性更改非常有用。

🌐 CLI flags are useful for one-off changes in CI or local debugging.

使用自定义忽略文件:

🌐 Use a custom ignore file:

bash
oxlint --ignore-path path/to/ignorefile

添加额外的忽略模式:

🌐 Add additional ignore patterns:

bash
oxlint --ignore-pattern 'dist/**' --ignore-pattern 'coverage/**'

使用引号模式以避免 shell 通配符扩展。

🌐 Quote patterns to avoid shell glob expansion.

取消忽略文件

🌐 Unignoring files

忽略文件支持否定模式,这允许忽略某个目录的同时保留特定文件。

🌐 Ignore files support negation patterns, which allow a directory to be ignored while keeping specific files.

要忽略 build/ 下的所有内容,但保留一个文件,请忽略内容而不是目录本身:

🌐 To ignore everything under build/ except one file, ignore the contents rather than the directory itself:

.oxlintrc.json
json
{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
  "ignorePatterns": ["build/**/*", "!build/keep.js"]
}

这在几乎忽略所有内容的同时仍然保持了可遍历性。

🌐 This keeps traversal possible while still ignoring almost everything.

禁用忽略

🌐 Disable ignoring

要禁用所有忽略行为,包括忽略文件和命令行忽略选项,请使用 --no-ignore

🌐 To disable all ignore behavior, including ignore files and CLI ignore options, use --no-ignore:

bash
oxlint --no-ignore