kieed
Biome | Formatter
Biome 格式化命令记录
当前博客是用 pnpm 构建的,
所以需要使用对应的命令。
1. 使用 —fix 参数
# 应用所有可自动修复的问题pnpm exec biome check --fix ./src# 或者pnpm exec biome lint --fix ./src2. 分步处理不同类型的问题
格式化问题
# 格式化代码pnpm exec biome format --write ./src代码质量检查
# 检查并修复代码质量问题pnpm exec biome lint --fix ./src不安全代码检查
# 检查并修复安全问题pnpm exec biome lint --unsafe ./src3. 查看详细报告
# 查看详细报告,了解具体问题pnpm exec biome ci --reporter=github ./src4. 配置文件中启用自动修复
在 biome.json 中配置:
{ "vcs": { "enabled": true, "clientKind": "git" }, "linter": { "enabled": true, "rules": { "recommended": true } }, "formatter": { "enabled": true }, "organizeImports": { "enabled": true }}5. 提交前自动修复
在 package.json 中添加脚本:
{ "scripts": { "prepare": "husky install", "lint:fix": "biome check --apply ./src" }}6. 其他问题
某些问题可能需要手动修复:
- 查看具体的 warning 信息
- 运行
pnpm exec biome check --write --unsafe尝试修复更多问题
对于特定规则,可以在 biome.json 中临时禁用:
{ "linter": { "rules": { "suspicious": { "noExplicitAny": "off" } } }}首先尝试
biome check --apply可以解决大部分自动修复的问题。
Biome | Formatter
https://kwensiu.github.io/blog/posts/biome-formatter/