代码检查
ShipSaaS 使用 Biome 进行代码格式化和代码检查,以确保项目保持一致的代码质量。
Biome 在项目根目录中通过 biome.json 进行配置,此配置强制执行一致的代码风格并捕获常见错误。
运行代码检查和格式化
Section titled “运行代码检查和格式化”检查代码质量
Section titled “检查代码质量”要检查您的代码而不进行更改:
bun run lint此命令将报告代码库中的任何代码检查错误或警告,并尝试自动修复问题。
要自动格式化您的代码:
bun run format此命令将根据项目的代码格式规则格式化所有支持的文件。
项目的 Biome 配置在 biome.json 中定义。以下是我们配置的简化视图:
biome.json
{ "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", "formatter": { "enabled": true, "indentStyle": "space", "indentWidth": 2, "lineWidth": 80 }, "organizeImports": { "enabled": true }, "linter": { "enabled": true, "rules": { "recommended": true, // 各种规则自定义... } }, "javascript": { "formatter": { "quoteStyle": "single", "trailingCommas": "es5", "semicolons": "always" } }}有关如何自定义规则配置的更多信息,请参考 Biome 代码检查规则文档。
Biome 与您的编辑器集成时效果最佳:
ShipSaaS 为 Biome 提供了预配置的 VSCode/Cursor 设置,这些设置确保:
- Biome 用作 JavaScript 和 TypeScript 文件的默认格式化器
- 保存时自动格式化文件
- 保存时组织导入语句
.vscode/settings.json
{ "editor.defaultFormatter": "biomejs.biome", "[javascript]": { "editor.defaultFormatter": "biomejs.biome" }, "[typescript]": { "editor.defaultFormatter": "biomejs.biome" }, "[typescriptreact]": { "editor.defaultFormatter": "biomejs.biome" }, "editor.formatOnSave": true, "editor.codeActionsOnSave": { "quickfix.biome": "explicit", "source.organizeImports.biome": "explicit" }}现在您了解了如何在 ShipSaaS 中维护代码质量,探索这些相关主题: