项目代码检查与格式化工具链介绍
本项目采用 Oxc 工具链 作为核心 lint 与格式化方案:
| 职责 | 工具 | 版本 | 配置文件 |
|---|---|---|---|
| 代码检查 (Lint) | Oxlint | ^1.60.0 | .oxlintrc.json |
| 代码格式化 (Format) | Oxfmt | ^0.45.0 | .oxfmtrc.json |
| 编辑器基础规范 | EditorConfig | — | .editorconfig |
| 任务编排 | Turborepo | — | turbo.json |
全仓库(含 Expo 应用
apps/native-ui-playground)已统一到 Oxlint,没有任何包再跑 ESLint。eslint-plugin-sort是唯一的例外——它通过 Oxlint 的jsPlugins桥接运行,不需要 ESLint 本体。
# 全仓库 lint(通过 Turborepo 并行执行各包的 lint 脚本)
pnpm lint
# 全仓库格式化
pnpm format
# 仅检查格式(不写入,适合 CI)
pnpm format:checkOxlint 使用 Rust 编写,相较 ESLint 有 50-100 倍 的性能优势,且无需安装额外的 parser。项目通过 .oxlintrc.json 进行配置,支持根级配置继承 + 子包 override 的分层模式。
.oxlintrc.json ← 根配置(所有包共享)
├── apps/*/.oxlintrc.json ← 五个应用(+ React / Sort 插件)
├── docs/*/.oxlintrc.json ← 各文档站(+ Next.js 插件)
├── packages/web/ui/*/.oxlintrc.json ← shadcn / antd / compose
├── packages/web/*/.oxlintrc.json ← admin-layouts / admin-theme / materials 等
└── packages/native/ui/.oxlintrc.json ← Native UI根 .oxlintrc.json 启用的插件:
node/handle-callback-err、node/no-path-concat 等)prefer-node-protocol、throw-new-error 等)*.ts / *.tsx 启用)— 类型安全规则Admin 应用与 UI 组件包在根配置基础上额外启用:
rules-of-hooks、exhaustive-deps、jsx-key 等)jsPlugins 桥接)— 排序规则
sort/destructuring-properties — 解构属性排序sort/import-members — import 成员排序sort/exports — export 排序sort/string-enums / sort/string-unions — 枚举/联合类型成员排序sort/type-properties — 类型属性排序文档站点额外启用 nextjs(Next.js 框架规则),部分站点还开了 jsx-a11y、jsdoc / promise,以各站自己的 .oxlintrc.json 为准。
| 规则 | 级别 | 说明 |
|---|---|---|
eqeqeq | error | 强制全等比较 |
no-console | warn | 禁止 console(scripts 目录豁免) |
no-unused-vars | error | 禁止未使用变量(_ 前缀豁免) |
prefer-const | error | 未重新赋值必须用 const |
no-var | error | 禁止 var |
typescript/consistent-type-imports | error | 强制使用 type 导入 |
typescript/no-explicit-any | off | 允许 any(不作硬性限制) |
complexity | error | 限制圈复杂度 |
max-depth / max-params | error | 限制嵌套深度与参数数量 |
| 包 | lint 脚本 |
|---|---|
根 (package.json) | turbo run lint |
apps/*、packages/** | oxlint --fix |
docs/* | oxlint(文档站不自动改写) |
@skyroc/scripts | oxlint --fix --ignore-pattern 'templates/**' |
Oxfmt 是 Oxc 工具链的格式化器,同样基于 Rust,性能极高。项目使用它替代了 Prettier,配置文件为根目录的 .oxfmtrc.json,全仓库共享一份配置。
根据 .oxfmtrc.json 的配置:
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": true,
"bracketSameLine": false,
"arrowParens": "avoid",
"endOfLine": "lf",
"singleAttributePerLine": false,
"jsdoc": true,
"sortImports": {
"partitionByNewline": true,
"newlinesBetween": false
},
"sortPackageJson": true
}| 配置项 | 值 | 说明 |
|---|---|---|
printWidth | 120 | 每行最大字符数 |
semi | true | 语句末尾加分号 |
singleQuote | true | 使用单引号 |
trailingComma | "none" | 不添加尾随逗号 |
arrowParens | "avoid" | 箭头函数单参数不加括号 |
endOfLine | "lf" | 统一使用 LF 换行符 |
jsdoc | true | 格式化 JSDoc 注释 |
sortImports | { partitionByNewline: true } | 自动排序 import 语句 |
sortPackageJson | true | 自动排序 package.json 字段 |
格式化会跳过以下目录/文件:
node_modules、dist、.turbo、.next、.cache、coveragepnpm-lock.yaml、routeTree.gen.ts.claude、.agents.editorconfig 确保不同编辑器之间的基础格式一致:
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
quote_type = single
[*.md]
trim_trailing_whitespace = falseturbo.json 中定义了 lint 任务:
{
"lint": {
"dependsOn": ["^build"],
"outputs": []
}
}dependsOn: ["^build"] — lint 任务会等待依赖包构建完成后再执行,确保类型信息可用outputs: [] — lint 不产生文件输出,不做缓存格式化 (format / format:check) 直接在根 package.json 调用 oxfmt,不经过 Turborepo,因为 Oxfmt 天然支持全仓库扫描。
pnpm lint
└─ turbo run lint
├─ apps/* → oxlint --fix
├─ packages/** → oxlint --fix
└─ docs/* → oxlint
pnpm format
└─ oxfmt (全仓库, .oxfmtrc.json)
pnpm format:check
└─ oxfmt --check (CI 模式, 仅检查不写入)package.json 中添加 "lint": "oxlint" 或 "lint": "oxlint --fix" 脚本.oxlintrc.json 覆盖/扩展根配置lint 脚本的包Last updated on