commit b51b7229a63c4b8e06729296caa60d010b45e626 Author: Zhongwei Li Date: Sun Nov 30 09:07:13 2025 +0800 Initial commit diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..759cd77 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,12 @@ +{ + "name": "biome-format", + "description": "biomeによるファイル保存時の自動コードフォーマット", + "version": "0.0.0-2025.11.28", + "author": { + "name": "TOYOTA, Yoichi", + "email": "y.toyota@xtone.co.jp" + }, + "hooks": [ + "./hooks" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8dc1096 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# biome-format + +biomeによるファイル保存時の自動コードフォーマット diff --git a/hooks/biome_format.sh b/hooks/biome_format.sh new file mode 100755 index 0000000..a3b04b8 --- /dev/null +++ b/hooks/biome_format.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# 対象ファイル拡張子のリスト +TARGET_EXTENSIONS=("ts" "tsx" "js" "jsx") + +# 標準入力からJSONデータを読み取り +input_data=$(cat) + +# ファイルパスを取得 +file_path=$(echo "$input_data" | jq -r '.tool_input.file_path') + +# 対象ファイル拡張子かチェック +is_target_file=false +for ext in "${TARGET_EXTENSIONS[@]}"; do + if [[ "$file_path" == *".$ext" ]]; then + is_target_file=true + break + fi +done + +if [ "$is_target_file" = false ]; then + echo "Not a target file extension: $file_path" + exit 0 +fi + +# ファイルパスを絶対パスに変換 +if [[ "$file_path" != /* ]]; then + file_path="$(pwd)/$file_path" +fi + +# ファイルが存在するかチェック +if [ ! -f "$file_path" ]; then + echo "File not found: $file_path" + exit 1 +fi + +# ファイルのディレクトリから上位ディレクトリへ遡ってbiome.jsonを探す +find_biome_config() { + local current_dir="$1" + + while [ "$current_dir" != "/" ]; do + if [ -f "$current_dir/biome.json" ]; then + echo "$current_dir" + return 0 + fi + current_dir=$(dirname "$current_dir") + done + + return 1 +} + +# ファイルのディレクトリを取得 +file_dir=$(dirname "$file_path") + +# biome.jsonを探す +config_dir=$(find_biome_config "$file_dir") + +if [ -z "$config_dir" ]; then + echo "biome.json not found, using default configuration" + echo "Formatting $file_path with Biome (default config)" + # デフォルト設定でbiome formatを実行 + npx @biomejs/biome format --write "$file_path" +else + echo "Found biome.json in: $config_dir" + echo "Formatting $file_path with Biome" + # biome.jsonがあるディレクトリに移動してから実行 + (cd "$config_dir" && npx @biomejs/biome format --write "$file_path") +fi \ No newline at end of file diff --git a/hooks/hooks.json b/hooks/hooks.json new file mode 100644 index 0000000..66c2288 --- /dev/null +++ b/hooks/hooks.json @@ -0,0 +1,15 @@ +{ + "hooks": { + "PostToolUse": [ + { + "matcher": "Write|Edit|MultiEdit", + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/hooks/biome_format.sh" + } + ] + } + ] + } +} diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..fb64be9 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,49 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:xtone/ai_development_tools:claude_code_hooks/biome_format", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "4cbe85cb9e152f03a896f5cdfb0b748ee8d168e2", + "treeHash": "f19c8a1fb91e38af3dc6a5579e902e29f7105f6ce681e373539d52d17aee5496", + "generatedAt": "2025-11-28T10:29:07.339210Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "biome-format", + "description": "biomeによるファイル保存時の自動コードフォーマット", + "version": null + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "f7d87a7bda9a466ad1fdcd85e8957a513bf9baa20e5b9268783996116af22b04" + }, + { + "path": "hooks/biome_format.sh", + "sha256": "9c8d373d17c3232014ea5e480bd26e602aa4852f4096cf19ad19e974b0f41604" + }, + { + "path": "hooks/hooks.json", + "sha256": "9c93110a9a473adf1124300abc5e8ab32962c1d5f6e5abb5d6500d7a9d1af62a" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "128bf1b25624ff17a13193d378e3258952b1720cecbfb58df1a3f07f4d0d0998" + } + ], + "dirSha256": "f19c8a1fb91e38af3dc6a5579e902e29f7105f6ce681e373539d52d17aee5496" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file