快速入门
🌐 Quickstart
本页展示了推荐的Oxlint设置方法及最常见的工作流程,并配有复制粘贴命令。
🌐 This page shows the recommended setup for Oxlint and the most common workflows, with copy-paste commands.
安装
🌐 Install
将 oxlint 安装为开发依赖:
🌐 Install oxlint as a dev dependency:
$ npm add -D oxlint$ pnpm add -D oxlint$ yarn add -D oxlint$ bun add -D oxlint向 package.json 添加 lint 命令:
🌐 Add lint commands to package.json:
{
"scripts": {
"lint": "oxlint",
"lint:fix": "oxlint --fix"
}
}运行它:
🌐 Run it:
pnpm run lint应用修复:
🌐 Apply fixes:
pnpm run lint:fix用法
🌐 Usage
有关完整的选项列表,请参阅 CLI 参考。
🌐 For the complete list of options, see the CLI reference.
oxlint [OPTIONS] [PATH]...如果省略 PATH,Oxlint 将检查当前工作目录。
🌐 If PATH is omitted, Oxlint lints the current working directory.
常见工作流程
🌐 Common workflows
使用 lint-staged 的预提交
🌐 Pre-commit with lint-staged
{
"lint-staged": {
"*.{js,jsx,ts,tsx,mjs,cjs}": "pnpm run lint"
}
}创建配置文件
🌐 Create a config file
使用默认值初始化 .oxlintrc.json 配置:
🌐 Initialize the .oxlintrc.json config with default values:
oxlint --init然后运行 Oxlint:
🌐 Then run Oxlint:
oxlintTIP
如果你正在从 ESLint 迁移,请参阅 从 ESLint 迁移 页面,获取关于迁移的详细指导。
解决问题
🌐 Fix problems
应用安全修复:
🌐 Apply safe fixes:
oxlint --fix应用建议(可能会改变程序行为):
🌐 Apply suggestions (may change program behavior):
oxlint --fix-suggestions应用危险修复和建议:
🌐 Apply dangerous fixes and suggestions:
oxlint --fix-dangerously请参阅 自动修复 了解何时使用每种模式的指南。
🌐 See Automatic fixes for guidance on when to use each mode.
忽略文件
🌐 Ignore files
使用显式忽略文件:
🌐 Use an explicit ignore file:
oxlint --ignore-path .oxlintignore从命令行添加忽略模式:
🌐 Add ignore patterns from the command line:
oxlint --ignore-pattern "dist/**" --ignore-pattern "*.min.js"禁用忽略处理:
🌐 Disable ignore handling:
oxlint --no-ignore请参阅 忽略文件。
🌐 See Ignore files.
可靠地使 CI 失败
🌐 Fail CI reliably
只报告错误:
🌐 Only report errors:
oxlint --quiet如果发现任何警告则失败:
🌐 Fail if any warnings are found:
oxlint --deny-warnings如果警告超过阈值则失败:
🌐 Fail if warnings exceed a threshold:
oxlint --max-warnings 0请参阅 CI 设置。
🌐 See CI setup.
使用机器可读的输出
🌐 Use machine-readable output
选择输出格式:
🌐 Select an output format:
oxlint -f json可用的格式包括:default、json、unix、checkstyle、github、gitlab、junit、stylish。
🌐 Available formats include: default, json, unix, checkstyle, github, gitlab, junit, stylish.
检查有效配置
🌐 Inspect the effective configuration
打印文件时将使用的配置:
🌐 Print the configuration that would be used for a file:
oxlint --print-config path/to/file.ts列出可用规则
🌐 List available rules
列出已注册的规则,包括当前 oxlint 配置启用的规则:
🌐 List registered rules, including those enabled by your current oxlint config:
oxlint --rules完整列表见规则参考。
🌐 The full list is in the Rules reference.
下一步
🌐 Next steps
