Biome をプロジェクトに導入した時、ほぼ必ず設定する npm-scripts のパターンだ。lint と format 両方を biome check コマンドで統一的に扱う。
基本設定
{ "scripts": { "lint": "biome check .", "format": "biome check . --write" }}プレフィックスでグループ化
npm-scripts が多いプロジェクトでは、プレフィックスでグループ化すると整理しやすい。
{ "scripts": { "code:lint": "biome check .", "code:format": "biome check . --write" }}コマンドの違い
| コマンド | 動作 |
|---|---|
| biome check . | 問題を検出してレポート、終了コードはエラー時に非ゼロ |
| biome check . —write | 自動修正可能な問題を修正 |
| biome format . | フォーマットのみ実行 |
| biome lint . | リントのみ実行 |
check は lint と format の両方を実行する。CI では check . を、開発時は —write を使うのが一般的だ。
CI での使用例
GitHub Actions での設定例:
- name: Check code run: npm run lint
- name: Check formatting run: npx biome format . --checkまたは check —changed で変更ファイルのみ検証:
{ "scripts": { "lint:changed": "biome check --changed ." }}これにより、差分のみを対象にして処理時間を短縮できる。
設定ファイルとの関係
biome.json で詳細な設定を行う:
{ "formatter": { "indentStyle": "space", "indentWidth": 2 }, "linter": { "enabled": true, "rules": { "recommended": true } }}npm-scripts はエントリーポイントとしてシンプルに保ち、詳細な設定は設定ファイルに委譲するのが良い。
hsb.horse