Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions .claude/commands/setup-husky.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Husky + lint-staged + commitlint 最小構成
Husky + lint-staged + commitlint + file-length 最小構成

コミット前に軽量な自動整形と静的チェックを行い、プッシュ前とCIで重い検証を実行します。

方針
• pre-commit: ステージ済みファイルに対して ESLint 自動修正と Prettier 整形を高速実行
• pre-commit: ステージ済みファイルに対して ESLint 自動修正、Prettier 整形、ファイル行数チェックを高速実行
• pre-push: 型チェックとテストを実行
• commit-msg: Conventional Commits を commitlint で検証
• npm --prefix next で一貫して next/ の依存を使用
• file-length: 500行以上のファイルはコミットをブロック、350行以上は警告

⸻

Expand All @@ -15,10 +16,26 @@ Husky + lint-staged + commitlint 最小構成
npm i -D husky lint-staged @commitlint/cli @commitlint/config-conventional
npm pkg set scripts.prepare="husky"
npm run prepare
npx husky add .husky/pre-commit "npx lint-staged"
npx husky add .husky/pre-commit "npx lint-staged && bash scripts/check-file-length.sh"
npx husky add .husky/commit-msg "npx commitlint --edit \$1"
npx husky add .husky/pre-push "npm --prefix next run type-check && npm --prefix next run test:ci"

# ファイル行数チェックの設定

mkdir -p scripts

# DevContainer 環境の場合

if [ -f /usr/local/script/check-file-length.sh ]; then
cp /usr/local/script/check-file-length.sh scripts/
fi
Comment on lines +29 to +31

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing chmod +x after copying check-file-length.sh.

cp does not reliably preserve the execute bit (it is subject to the process's umask). Without an explicit chmod +x, the copied script may not be executable, causing the pre-commit hook to fail with Permission denied. The corresponding automated path in setup-file-length-check.sh does include chmod +x scripts/check-file-length.sh; the manual snippet should match:

🔧 Proposed fix
 if [ -f /usr/local/script/check-file-length.sh ]; then
 cp /usr/local/script/check-file-length.sh scripts/
+chmod +x scripts/check-file-length.sh
 fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ -f /usr/local/script/check-file-length.sh ]; then
cp /usr/local/script/check-file-length.sh scripts/
fi
if [ -f /usr/local/script/check-file-length.sh ]; then
cp /usr/local/script/check-file-length.sh scripts/
chmod +x scripts/check-file-length.sh
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/commands/setup-husky.md around lines 29 - 31, The snippet that
copies check-file-length.sh doesn't make the file executable; after the cp in
the conditional block that copies /usr/local/script/check-file-length.sh to
scripts/, run an explicit chmod +x on scripts/check-file-length.sh (matching the
approach used in setup-file-length-check.sh) so the pre-commit hook can execute
without permission errors.


# テンプレートから .filelengthignore をコピー

if [ -f /usr/local/share/config-templates/.filelengthignore.template ]; then
cp /usr/local/share/config-templates/.filelengthignore.template .filelengthignore
fi

⸻

必要な npm scripts(next/package.json)
Expand Down Expand Up @@ -119,10 +136,29 @@ Husky の再初期化

rm -rf .husky
npm run prepare
npx husky add .husky/pre-commit "npx lint-staged"
npx husky add .husky/pre-commit "npx lint-staged && bash scripts/check-file-length.sh"
npx husky add .husky/commit-msg "npx commitlint --edit \$1"
npx husky add .husky/pre-push "npm --prefix next run type-check && npm --prefix next run test:ci"

⸻

ファイル行数チェックの設定

• 警告閾値: FILE_LENGTH_WARN_LIMIT=350 (デフォルト)
• エラー閾値: FILE_LENGTH_HARD_LIMIT=500 (デフォルト)
• 除外設定: .filelengthignore(.gitignore と同じ記法)

.filelengthignore の例:

# 自動生成ファイル

**/_.generated._
**/database.types.ts
Comment on lines +153 to +156

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Glob pattern corrupted by Markdown italic rendering.

**/_.generated._ will render as **/ followed by italic _generated_ followed by nothing — the * delimiters are consumed by the Markdown parser. Users who copy this pattern will get a broken .filelengthignore entry. Wrap the example block in a fenced code block, or at minimum escape the asterisks:

🔧 Proposed fix
-**/_.generated._
+**/*.generated.*

Or wrap the entire example in a fenced code block to prevent Markdown interpretation:

# 自動生成ファイル
**/*.generated.*
**/database.types.ts
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# 自動生成ファイル
**/_.generated._
**/database.types.ts
# 自動生成ファイル
**/*.generated.*
**/database.types.ts
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/commands/setup-husky.md around lines 153 - 156, The markdown entry
`**/_.generated._` is being rendered incorrectly due to Markdown treating `*`
and `_` as emphasis; update the example so the glob is shown literally—either
wrap the snippet in a fenced code block or escape the asterisks/underscores
(e.g., replace with `**/*.generated.*` or escape characters) to ensure the
`.filelengthignore` pattern copies correctly; edit the text containing the glob
pattern (`**/_.generated._`) to use a fenced code block or the escaped form.


# 複雑なステートマシン

src/contexts/complex-context.tsx

一時的にフックをスキップ

git commit --no-verify -m "urgent: emergency fix"
1 change: 1 addition & 0 deletions .claude/skills/find-skills
1 change: 1 addition & 0 deletions .claude/skills/react-doctor
3 changes: 3 additions & 0 deletions .claude/skills/skills.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# React 公式スキル
facebook/react@fix

# React コードベース診断・修正ツール
millionco/react-doctor

# === Vercel Agent Skills ===
# React/Next.js 開発のベストプラクティス
vercel-labs/agent-skills
Expand Down
1 change: 1 addition & 0 deletions .claude/skills/supabase-postgres-best-practices
14 changes: 14 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM mcr.microsoft.com/devcontainers/base:ubuntu

# Build arguments
ARG CLAUDE_CODE_OAUTH_TOKEN

Check warning on line 4 in .devcontainer/Dockerfile

View workflow job for this annotation

GitHub Actions / Trivy Container Scan

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "CLAUDE_CODE_OAUTH_TOKEN") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

Check warning on line 4 in .devcontainer/Dockerfile

View workflow job for this annotation

GitHub Actions / Generate SBOM

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "CLAUDE_CODE_OAUTH_TOKEN") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ARG ANTHROPIC_API_KEY

Check warning on line 5 in .devcontainer/Dockerfile

View workflow job for this annotation

GitHub Actions / Trivy Container Scan

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "ANTHROPIC_API_KEY") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

Check warning on line 5 in .devcontainer/Dockerfile

View workflow job for this annotation

GitHub Actions / Generate SBOM

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "ANTHROPIC_API_KEY") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ARG IMAGE_VERSION="dev"

# OCI Image Labels for version tracking
Expand Down Expand Up @@ -31,6 +31,7 @@
python3-venv \
python3-dev \
apt-transport-https \
unzip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -42,6 +43,17 @@
&& dpkg -i /tmp/doppler.deb \
&& rm /tmp/doppler.deb

# Install 1Password CLI (op)
# https://developer.1password.com/docs/cli/get-started/
RUN OP_VERSION="2.32.1" \
&& ARCH=$(dpkg --print-architecture) \
&& curl -sSfo /tmp/op.zip "https://cache.agilebits.com/dist/1P/op2/pkg/v${OP_VERSION}/op_linux_${ARCH}_v${OP_VERSION}.zip" \
&& unzip -od /usr/local/bin/ /tmp/op.zip \
&& rm /tmp/op.zip \
&& groupadd -f onepassword-cli \
&& chown root:onepassword-cli /usr/local/bin/op \
&& chmod g+s /usr/local/bin/op

# Install Node.js
RUN NODE_VERSION=v22.14.0 \
&& NODE_ARCH=$(dpkg --print-architecture | sed 's/amd64/x64/;s/armhf/armv7l/;s/arm64/arm64/') \
Expand Down Expand Up @@ -128,6 +140,8 @@
COPY --chown=vscode:vscode script/lib /tmp/script/lib
COPY --chown=root:root script/lib /usr/local/script/lib
COPY --chown=root:root script/*.sh /usr/local/script/
# Copy templates for project initialization
COPY --chown=root:root .devcontainer/templates /usr/local/share/config-templates/
RUN chmod +x /usr/local/bin/setup-claude.sh /tmp/setup-claude-build.sh /tmp/install-skills.sh /usr/local/script/*.sh

# Install skills from skills.txt using npx skills add
Expand Down
31 changes: 31 additions & 0 deletions .devcontainer/templates/.filelengthignore.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# .filelengthignore - 行数チェック (check-file-length.sh) の除外パターン
#
# .gitignore と同じ記法でパターンを指定できます。
# - 空行とコメント行 (#) は無視されます
# - glob パターンが使えます(*, **, ? など)
# - パスはリポジトリルートからの相対パスで評価されます
#
# 例:
# src/lib/types/database.ts # 完全パス指定
# **/*.generated.ts # glob パターン
# **/schema.sql # 任意の階層

# 自動生成ファイル
**/*.generated.*
**/*.gen.*
**/database.types.ts

# ビルド出力
dist/**
build/**
.next/**
node_modules/**

# テスト関連
**/*.test.ts
**/*.spec.ts
**/coverage/**

# 設定ファイル
**/package-lock.json
**/pnpm-lock.yaml
17 changes: 10 additions & 7 deletions script/check-file-length.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#!/usr/bin/env bash
#
# ============================================================================
# check-file-length.sh - ステージされたファイルの行数チェック
#
# ファイルが長すぎる場合に警告またはエラーを出力します。
# 除外パターンは .filelengthignore で管理(.gitignore と同じ記法)
#
# ============================================================================

set -euo pipefail

HARD_LIMIT=500
WARN_LIMIT=350
REPO_ROOT="$(git rev-parse --show-toplevel)"
HARD_LIMIT=${FILE_LENGTH_HARD_LIMIT:-500}
WARN_LIMIT=${FILE_LENGTH_WARN_LIMIT:-350}
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
IGNORE_FILE="$REPO_ROOT/.filelengthignore"

# ステージされた TS/JS ファイル(削除以外)を取得
staged_files() {
git diff --cached --name-only --diff-filter=d -- \
'*.ts' '*.tsx' '*.js' '*.jsx'
'*.ts' '*.tsx' '*.js' '*.jsx' 2>/dev/null || true
}

# .filelengthignore のパターンで除外判定(git check-ignore を .gitignore 記法で流用)
Expand All @@ -33,7 +34,7 @@ while IFS= read -r file; do
[ -z "$file" ] && continue
is_ignored "$file" && continue

line_count=$(git show ":$file" 2>/dev/null | wc -l)
line_count=$(git show ":$file" 2>/dev/null | wc -l | tr -d ' ')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

set -euo pipefail + failed git show will abort the hook and falsely block commits.

With pipefail active, if git show ":$file" exits non-zero (e.g. for a binary file, an encoding edge case, or a transient git issue), the pipeline's exit code propagates to the assignment, which—at statement level inside the loop—triggers set -e and kills the script. The commit is then blocked with no meaningful error message.

Adding || continue converts a fatal abort into a graceful skip for the problematic file:

🔧 Proposed fix
-  line_count=$(git show ":$file" 2>/dev/null | wc -l | tr -d ' ')
+  line_count=$(git show ":$file" 2>/dev/null | wc -l | tr -d ' ') || continue
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
line_count=$(git show ":$file" 2>/dev/null | wc -l | tr -d ' ')
line_count=$(git show ":$file" 2>/dev/null | wc -l | tr -d ' ') || continue
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@script/check-file-length.sh` at line 37, The pipeline that computes
line_count using "git show ":$file" | wc -l" will cause the script to abort
under set -euo pipefail when git show returns non-zero; modify the command that
defines line_count in check-file-length.sh (the line assigning to line_count and
referencing $file) to append "|| continue" so that a failing git show is treated
as a skip for that file instead of killing the script, ensuring the loop
continues on problematic files.


if [ "$line_count" -ge "$HARD_LIMIT" ]; then
errors+=(" ❌ ${file} (${line_count}行)")
Expand All @@ -60,3 +61,5 @@ if [ ${#errors[@]} -gt 0 ]; then
echo " 2. .filelengthignore に除外パターンを追加する"
exit 1
fi

exit 0
88 changes: 88 additions & 0 deletions script/setup-file-length-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env bash
# ============================================================================
# setup-file-length-check.sh - ファイル行数チェックのセットアップ
#
# 使用方法:
# ./setup-file-length-check.sh # カレントディレクトリにセットアップ
# ./setup-file-length-check.sh /path # 指定ディレクトリにセットアップ
# ============================================================================

set -euo pipefail

TARGET_DIR="${1:-.}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEMPLATE_DIR="/usr/local/share/config-templates"

echo "[INFO] ファイル行数チェックをセットアップします..."

# ターゲットディレクトリに移動
cd "$TARGET_DIR"

# scripts ディレクトリを作成
mkdir -p scripts

# check-file-length.sh をコピー
if [ -f "$SCRIPT_DIR/check-file-length.sh" ]; then
cp "$SCRIPT_DIR/check-file-length.sh" scripts/
chmod +x scripts/check-file-length.sh
echo "[SUCCESS] scripts/check-file-length.sh をコピーしました"
elif [ -f /usr/local/script/check-file-length.sh ]; then
cp /usr/local/script/check-file-length.sh scripts/
chmod +x scripts/check-file-length.sh
echo "[SUCCESS] scripts/check-file-length.sh をコピーしました"
else
echo "[ERROR] check-file-length.sh が見つかりません"
exit 1
fi

# .filelengthignore をコピー(存在しない場合のみ)
if [ ! -f .filelengthignore ]; then
if [ -f "$TEMPLATE_DIR/.filelengthignore.template" ]; then
cp "$TEMPLATE_DIR/.filelengthignore.template" .filelengthignore
Comment on lines +40 to +41

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Read repo template before writing fallback ignore list

setup-file-length-check.sh only looks for .filelengthignore.template under /usr/local/share/config-templates and otherwise writes a reduced hardcoded fallback, so running the script directly from this repo (or any non-devcontainer environment) produces different ignore rules than the bundled template and can unexpectedly block commits for files that should be excluded. Please check a local bundled template path before falling back to the minimal inline content.

Useful? React with 👍 / 👎.

echo "[SUCCESS] .filelengthignore を作成しました"
else
# テンプレートがない場合は最小限の内容で作成
cat > .filelengthignore << 'IGNORE'
# .filelengthignore - 行数チェックの除外パターン
# .gitignore と同じ記法でパターンを指定

# 自動生成ファイル
**/*.generated.*
**/*.gen.*

# ビルド出力
dist/**
build/**
.next/**
node_modules/**
IGNORE
echo "[SUCCESS] .filelengthignore を作成しました(デフォルト)"
fi
else
echo "[INFO] .filelengthignore は既に存在します"
fi

# Husky pre-commit に追加(.husky/pre-commit が存在する場合)
if [ -f .husky/pre-commit ]; then
if ! grep -q "check-file-length.sh" .husky/pre-commit; then
{
echo ""
echo "echo \"[husky] Running file length check...\""
echo "bash scripts/check-file-length.sh || exit 1"
} >> .husky/pre-commit
echo "[SUCCESS] .husky/pre-commit に filelength チェックを追加しました"
else
echo "[INFO] .husky/pre-commit には既に filelength チェックが含まれています"
fi
else
echo "[INFO] .husky/pre-commit が見つかりません(手動で追加してください)"
echo " npx husky add .husky/pre-commit \"bash scripts/check-file-length.sh\""
fi

echo ""
echo "[SUCCESS] ファイル行数チェックのセットアップが完了しました"
echo ""
echo "設定:"
echo " - 警告閾値: 350行(FILE_LENGTH_WARN_LIMIT で変更可)"
echo " - エラー閾値: 500行(FILE_LENGTH_HARD_LIMIT で変更可)"
echo " - 除外設定: .filelengthignore"
Loading