mcpField
B
biome

biome

github.com/bobmatnycテスト・品質78933 回インストール15 週間前に更新
リポジトリ

biome について

Biomeは、Webプロジェクト向けのRust製ツールチェーンで、コードのフォーマットとLintをまとめて行えます。JavaScriptやTypeScriptを扱う開発者向けで、インポート整理やモノレポ対応を備えています。

主な機能

  1. 01フォーマットとLintの統合
  2. 02インポートの自動整理
  3. 03TypeScriptを優先サポート
  4. 04モノレポ対応
  5. 05VS Code連携

活用シーン

  1. 01Webプロジェクトのコード検査と整形
  2. 02コミット前の問題の自動修正
  3. 03モノレポ全体への共通ルール適用

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/bobmatnyc/claude-mpm-skills --skill biome

インストール後、Claude Code で/biomeを入力して読み込まれたか確認します。

同梱ファイルmetadata.json

詳細

Biome - 高速なオールインワンツールチェーン

概要

Biomeは、Rustで書かれたWebプロジェクト向けの高速なオールインワンツールチェーンです。ESLintとPrettierの両方を、100倍高速で、設定不要のデフォルト設定を備えた単一のツールに置き換えます。

主な機能:

  • リントとフォーマットを1つのツールで実行
  • ESLintより100倍高速
  • デフォルトで設定不要
  • インポートの並べ替え機能を内蔵
  • TypeScriptを第一に考えた設計
  • Prettierとの部分的な互換性
  • モノレポを標準でサポート
  • VS Codeとの統合

インストール:

npm install --save-dev @biomejs/biome

クイックスタート

1. Biomeを初期化する
# Create biome.json configuration
npx @biomejs/biome init

# Check your project
npx @biomejs/biome check .

# Fix issues automatically
npx @biomejs/biome check --write .

# Format only
npx @biomejs/biome format --write .

# Lint only
npx @biomejs/biome lint .
2. package.jsonのスクリプト
{
  "scripts": {
    "check": "biome check .",
    "check:write": "biome check --write .",
    "format": "biome format --write .",
    "lint": "biome lint .",
    "lint:fix": "biome lint --write ."
  }
}
3. 基本設定
{
  "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
  "vcs": {
    "enabled": true,
    "clientKind": "git",
    "useIgnoreFile": true
  },
  "files": {
    "ignoreUnknown": false,
    "ignore": ["node_modules", "dist", "build", ".next"]
  },
  "formatter": {
    "enabled": true,
    "indentStyle": "space",
    "indentWidth": 2,
    "lineWidth": 100
  },
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true
    }
  },
  "javascript": {
    "formatter": {
      "quoteStyle": "single",
      "semicolons": "asNeeded",
      "trailingCommas": "all"
    }
  }
}

主なコマンド

Checkコマンド(推奨)

checkコマンドはリントとフォーマットの両方を実行します。

# Check all files
biome check .

# Fix issues automatically
biome check --write .

# Unsafe fixes (may change behavior)
biome check --write --unsafe .

# Apply suggested fixes
biome check --write --unsafe --apply-suggested

# Check specific files
biome check src/**/*.ts

# CI mode (exit with error on issues)
biome ci .
Formatコマンド

リントせずにコードをフォーマットします。

# Format all files
biome format --write .

# Check formatting without changing files
biome format .

# Format specific files
biome format --write src/**/*.{ts,tsx,js,jsx}

# Format stdin
echo "const x={a:1}" | biome format --stdin-file-path=file.js
Lintコマンド

フォーマットせずにコードをリントします。

# Lint all files
biome lint .

# Fix linting issues
biome lint --write .

# Show rule names
biome lint --verbose .

# Apply unsafe fixes
biome lint --write --unsafe .

設定の詳細

フォーマッターの設定
{
  "formatter": {
    "enabled": true,
    "formatWithErrors": false,
    "indentStyle": "space",
    "indentWidth": 2,
    "lineEnding": "lf",
    "lineWidth": 80,
    "attributePosition": "auto"
  },
  "javascript": {
    "formatter": {
      "quoteStyle": "single",
      "jsxQuoteStyle": "double",
      "quoteProperties": "asNeeded",
      "trailingCommas": "all",
      "semicolons": "asNeeded",
      "arrowParentheses": "always",
      "bracketSpacing": true,
      "bracketSameLine": false
    }
  },
  "json": {
    "formatter": {
      "trailingCommas": "none"
    }
  }
}
リンターの設定
{
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true,
      "a11y": {
        "recommended": true,
        "noAutofocus": "error",
        "useKeyWithClickEvents": "warn"
      },
      "complexity": {
        "recommended": true,
        "noForEach": "off",
        "useLiteralKeys": "error"
      },
      "correctness": {
        "recommended": true,
        "noUnusedVariables": "error",
        "useExhaustiveDependencies": "warn"
      },
      "performance": {
        "recommended": true,
        "noAccumulatingSpread": "warn"
      },
      "security": {
        "recommended": true,
        "noDangerouslySetInnerHtml": "error"
      },
      "style": {
        "recommended": true,
        "noNonNullAssertion": "warn",
        "useConst": "error",
        "useTemplate": "warn"
      },
      "suspicious": {
        "recommended": true,
        "noExplicitAny": "warn",
        "noArrayIndexKey": "error"
      }
    }
  }
}
ファイルの除外パターン
{
  "files": {
    "ignore": [
      "node_modules",
      "dist",
      "build",
      ".next",
      "coverage",
      "*.min.js",
      "public/assets/**"
    ],
    "ignoreUnknown": false,
    "include": ["src/**/*.ts", "src/**/*.tsx"]
  }
}
特定のファイルに対する設定の上書き
{
  "overrides": [
    {
      "include": ["**/*.test.ts", "**/*.spec.ts"],
      "linter": {
        "rules": {
          "suspicious": {
            "noExplicitAny": "off"
          }
        }
      }
    },
    {
      "include": ["scripts/**/*.js"],
      "formatter": {
        "lineWidth": 120
      }
    }
  ]
}

VS Codeとの統合

1. Biome拡張機能をインストールする
# Install from VS Code marketplace
code --install-extension biomejs.biome
2. VS Codeの設定(.vscode/settings.json)
{
  "[javascript]": {
    "editor.defaultFormatter": "biomejs.biome",
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "quickfix.biome": "explicit",
      "source.organizeImports.biome": "explicit"
    }
  },
  "[typescript]": {
    "editor.defaultFormatter": "biomejs.biome",
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "quickfix.biome": "explicit",
      "source.organizeImports.biome": "explicit"
    }
  },
  "[typescriptreact]": {
    "editor.defaultFormatter": "biomejs.biome",
    "editor.formatOnSave": true
  },
  "[json]": {
    "editor.defaultFormatter": "biomejs.biome",
    "editor.formatOnSave": true
  },
  "biome.lspBin": "./node_modules/@biomejs/biome/bin/biome"
}
3. ワークスペースの設定
{
  "editor.formatOnSave": true,
  "editor.formatOnPaste": true,
  "editor.defaultFormatter": "biomejs.biome",
  "biome.rename": true,
  "files.autoSave": "onFocusChange"
}

ESLintとPrettierからの移行

1. 旧ツールを削除する
# Remove ESLint and Prettier
npm uninstall eslint prettier eslint-config-prettier \
  eslint-plugin-react eslint-plugin-import \
  @typescript-eslint/parser @typescript-eslint/eslint-plugin

# Remove configuration files
rm .eslintrc.js .eslintrc.json .prettierrc .prettierignore
2. 設定を移行する

Biomeの移行ツールを使用します。

# Migrate from Prettier config
biome migrate prettier --write

# Migrate from ESLint config
biome migrate eslint --write
3. 手動で移行する

Prettier → Biomeフォーマッター:

// .prettierrc (old)
{
  "semi": false,
  "singleQuote": true,
  "trailingComma": "all",
  "printWidth": 100
}

// biome.json (new)
{
  "formatter": {
    "lineWidth": 100
  },
  "javascript": {
    "formatter": {
      "semicolons": "asNeeded",
      "quoteStyle": "single",
      "trailingCommas": "all"
    }
  }
}

ESLint → Biomeリンター:

// .eslintrc.json (old)
{
  "rules": {
    "no-unused-vars": "error",
    "prefer-const": "warn"
  }
}

// biome.json (new)
{
  "linter": {
    "rules": {
      "correctness": {
        "noUnusedVariables": "error"
      },
      "style": {
        "useConst": "warn"
      }
    }
  }
}
4. スクリプトを更新する
{
  "scripts": {
    "lint": "biome lint .",
    "lint:fix": "biome lint --write .",
    "format": "biome format --write .",
    "check": "biome check --write ."
  }
}

Gitフックとの統合

Husky + lint-stagedを使用する
# Install dependencies
npm install --save-dev husky lint-staged
npx husky init

.husky/pre-commit:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged

package.json:

{
  "lint-staged": {
    "*.{js,ts,jsx,tsx,json}": [
      "biome check --write --no-errors-on-unmatched"
    ]
  }
}
Lefthookを使用する

lefthook.yml:

pre-commit:
  commands:
    lint:
      glob: "*.{js,ts,jsx,tsx,json}"
      run: biome check --write --no-errors-on-unmatched {staged_files}
シンプルなGitフック(依存関係なし)

.git/hooks/pre-commit:

#!/bin/bash

# Get staged files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|ts|jsx|tsx|json)$')

if [ -n "$STAGED_FILES" ]; then
  echo "Running Biome on staged files..."
  npx @biomejs/biome check --write --no-errors-on-unmatched $STAGED_FILES

  # Add formatted files back to staging
  git add $STAGED_FILES
fi

CI/CDとの統合

GitHub Actions
name: Biome CI

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  biome:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run Biome CI
        run: npx @biomejs/biome ci .

      - name: Check formatting
        run: npx @biomejs/biome format .

      - name: Lint
        run: npx @biomejs/biome lint .
GitLab CI
biome:
  image: node:20-alpine
  stage: test
  script:
    - npm ci
    - npx @biomejs/biome ci .
  cache:
    paths:
      - node_modules/
  only:
    - merge_requests
    - main
CircleCI
version: 2.1

jobs:
  biome:
    docker:
      - image: cimg/node:20.11
    steps:
      - checkout
      - restore_cache:
          keys:
            - deps-{{ checksum "package-lock.json" }}
      - run: npm ci
      - save_cache:
          paths:
            - node_modules
          key: deps-{{ checksum "package-lock.json" }}
      - run: npx @biomejs/biome ci .

workflows:
  test:
    jobs:
      - biome

インポートの並べ替え

Biomeにはインポートの並べ替え機能が組み込まれています。

# Organize imports
biome check --write --organize-imports-enabled=true .

設定:

{
  "organizeImports": {
    "enabled": true
  }
}

例:

// Before
import { useState } from 'react';
import axios from 'axios';
import { Button } from './components/Button';
import type { User } from './types';
import './styles.css';

// After (sorted)
import type { User } from './types';

import axios from 'axios';
import { useState } from 'react';

import { Button } from './components/Button';

import './styles.css';

TypeScriptのサポート

BiomeはTypeScriptを第一級でサポートしています。

{
  "linter": {
    "rules": {
      "suspicious": {
        "noExplicitAny": "warn",
        "noUnsafeDeclarationMerging": "error"
      },
      "correctness": {
        "noUnusedVariables": "error"
      },
      "style": {
        "useImportType": "error",
        "useExportType": "error"
      }
    }
  }
}

型を考慮したリント:

// Biome detects unused variables
const unused = 123; // ❌ Error

// Enforces type imports
import { User } from './types'; // ❌ Error
import type { User } from './types'; // ✅ Correct

// Detects unsafe type assertions
const num = "123" as any as number; // ⚠️ Warning

モノレポのサポート

Biomeはモノレポでも快適に動作します。

プロジェクト構成
my-monorepo/
├── biome.json (root config)
├── packages/
│   ├── web/
│   │   └── biome.json (extends root)
│   ├── api/
│   │   └── biome.json
│   └── shared/
│       └── biome.json
ルート設定
{
  "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
  "extends": [],
  "formatter": {
    "enabled": true,
    "indentStyle": "space",
    "indentWidth": 2
  },
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true
    }
  }
}
パッケージ設定の上書き
{
  "extends": ["../../biome.json"],
  "formatter": {
    "lineWidth": 100
  },
  "linter": {
    "rules": {
      "style": {
        "noNonNullAssertion": "off"
      }
    }
  }
}
モノレポのスクリプト
{
  "scripts": {
    "check": "biome check .",
    "check:packages": "biome check packages/*",
    "format": "biome format --write .",
    "lint": "biome lint packages/*"
  }
}

パフォーマンス上の利点

速度の比較
ツール時間(10,000ファイル)
ESLint + Prettier~60s
Biome~0.6s

一般的なワークロードで平均100倍高速です。

キャッシュ

Biomeにはインテリジェントなキャッシュ機能があります。

# First run (no cache)
biome check .  # 1.2s

# Second run (with cache)
biome check .  # 0.1s

# Clear cache
rm -rf node_modules/.cache/biome
並列処理

BiomeはデフォルトですべてのCPUコアを使用します。

# Limit CPU cores
biome check --max-diagnostics=50 .

# Verbose output
biome check --verbose .

よくあるパターン

Reactプロジェクト
{
  "linter": {
    "rules": {
      "a11y": {
        "recommended": true,
        "useButtonType": "error",
        "useKeyWithClickEvents": "error"
      },
      "correctness": {
        "useExhaustiveDependencies": "warn",
        "useHookAtTopLevel": "error"
      },
      "suspicious": {
        "noArrayIndexKey": "error"
      }
    }
  },
  "javascript": {
    "formatter": {
      "jsxQuoteStyle": "double"
    }
  }
}
Next.jsプロジェクト
{
  "files": {
    "ignore": [".next", "out", "node_modules"]
  },
  "overrides": [
    {
      "include": ["app/**/*.tsx", "pages/**/*.tsx"],
      "linter": {
        "rules": {
          "a11y": {
            "recommended": true
          }
        }
      }
    }
  ]
}
Node.jsバックエンド
{
  "linter": {
    "rules": {
      "security": {
        "recommended": true,
        "noGlobalEval": "error"
      },
      "correctness": {
        "noUnusedVariables": "error"
      }
    }
  },
  "javascript": {
    "formatter": {
      "semicolons": "always"
    }
  }
}

ベストプラクティス

  1. formatコマンドとlintコマンドを個別に実行する代わりに、biome checkを使用します
  2. 自動修正するには--writeフラグを有効にします
  3. 保存時にフォーマットするようVS Codeを設定します
  4. コミット前に品質を確保するため、Gitフックを追加します
  5. 継続的インテグレーションではCIモード(biome ci)を使用します
  6. 推奨ルールから始めて、必要に応じてカスタマイズします
  7. インポートの並べ替え機能を活用して、インポートを自動的に整理します
  8. ファイルの種類やディレクトリに応じて上書き設定を使用します
  9. VCS統合を有効にして、.gitignoreを適用します
  10. 設定は最小限に抑えます。Biomeには優れたデフォルト設定があります

トラブルシューティング

Biomeがフォーマットしない
# Check if formatter is enabled
biome rage

# Verify file is not ignored
biome check --verbose src/file.ts

# Check VS Code extension logs
# View → Output → Biome
Prettierとの競合
# Disable Prettier in VS Code settings
"[javascript]": {
  "editor.defaultFormatter": "biomejs.biome"
}

# Remove Prettier dependencies
npm uninstall prettier
パフォーマンスの問題
# Check cache location
biome rage

# Clear cache
rm -rf node_modules/.cache/biome

# Reduce max diagnostics
biome check --max-diagnostics=20 .
ルール設定が機能しない
// Ensure correct category
{
  "linter": {
    "rules": {
      "correctness": {  // Category name matters
        "noUnusedVariables": "error"
      }
    }
  }
}

ローカルの Biome 設定(ご自身のリポジトリ)

進行中のプロジェクトで使われているパターン:

  • ai-code-review/biome.json:files.includes は src/**/*.ts を対象とし、テストを除外します。lineWidth: 100、シングルクォート、セミコロンは常に使用、noExplicitAny: warn という設定です。
  • itinerizer-ts/biome.json:files.ignore に node_modules、dist、.claude、データディレクトリが含まれます。organizeImports.enabled = true です。
  • matsuoka-com と diogenes では、同様のフォーマットのデフォルト(インデント 2 スペース、lineWidth 100)を使用しています。

共通スクリプト:

{
  "lint": "biome check src/ --diagnostic-level=error",
  "lint:fix": "biome check src/ --write",
  "format": "biome format src/ --write"
}

リソース

まとめ

  • Biome は高速なオールインワンのリンター兼フォーマッターです
  • ESLint + Prettier より 100 倍高速です
  • スマートなデフォルト設定により、デフォルトでは 設定不要です
  • 最高のパフォーマンスを実現するため、Rust で構築されています
  • TypeScript を第一に考えており、優れた型サポートを備えています
  • インポートの並べ替えが標準で含まれています
  • 公式拡張機能による VS Code 連携に対応しています
  • モダンな Web プロジェクト、モノレポ、CI/CD に 最適です
  • ESLint と Prettier から 簡単に移行できます

コメント