Are you an LLM? You can read better optimized documentation at /notes/biome.md for this page in Markdown format
为项目添加 Biome
1. 配置 Biome 格式化代码
安装 Biome
shell
pnpm add --save-dev @biomejs/biomeshell
npm install --save-dev @biomejs/biomeshell
yarn add --dev @biomejs/biomeBiome 配置
新建 biome.json 配置如下
biome.json
json
{
"$schema": "https://biomejs.dev/schemas/2.5.3/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": true,
"includes": ["**", "!node_modules", "!.vitepress/cache", "!.vitepress/dist", "!dist", "!cache", "!temp", "!.temp"]
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 120
},
"assist": {
"enabled": true,
"actions": {
"source": {
"organizeImports": "on"
}
}
},
"linter": {
"enabled": false
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"semicolons": "asNeeded",
"trailingCommas": "none"
}
},
"json": {
"formatter": {
"trailingCommas": "none"
}
},
"css": {
"formatter": {
"quoteStyle": "single"
}
}
}使用 Biome 格式化所有文件
shell
pnpm exec biome check --write .shell
npx @biomejs/biome check --write .shell
yarn biome check --write .配置 commit 自动格式化
安装 simple-git-hooks 和 lint-staged 插件
zsh
pnpm install simple-git-hooks lint-staged配置 package.json 示例
json
{
"lint-staged": {
"*": "biome check --write --no-errors-on-unmatched"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
}
}