feat: Add code quality rules and pre-commit lint hook#3
Conversation
git履歴分析から抽出した6つの再発防止ルールを.claude/rules/に追加し、 git commit前にnpm run lintを自動実行するClaude Code hookを設定。 - .claude/rules/code-quality.md: DB変更同期、any型禁止、prop名規約等 - .claude/hooks/pre-commit-lint.sh: PreToolUseフックでlint自動実行 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello @kwrkb, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! このプルリクエストは、開発ワークフローにコード品質保証の仕組みを導入し、プロジェクト全体のコード品質向上を目指しています。具体的には、コミット前に自動でリンティングを実行するフックを追加し、開発者がコード品質ルールを遵守するためのガイドラインを明文化することで、将来的な技術的負債の蓄積を防ぎ、より堅牢で保守しやすいコードベースを構築することを目的としています。 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
レビュー結果ファイル(status/review.md)をgit管理対象外にする。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| INPUT=$(cat) | ||
| COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty') |
| LINT_OUTPUT=$(npm run lint 2>&1) | ||
| EXIT_CODE=$? | ||
|
|
||
| if [ $EXIT_CODE -ne 0 ]; then |
There was a problem hiding this comment.
npm run lint を実行し、その終了コードを別の変数に保存して if でチェックする代わりに、if の条件式で直接コマンドの成否を判定する方がより簡潔で一般的なシェルスクリプトの書き方です。if ! LINT_OUTPUT=$(...); then のように書くことで、コマンドが失敗した場合(終了コードが非ゼロ)にのみブロック内が実行され、同時に出力もキャプチャできます。
| LINT_OUTPUT=$(npm run lint 2>&1) | |
| EXIT_CODE=$? | |
| if [ $EXIT_CODE -ne 0 ]; then | |
| if ! LINT_OUTPUT=$(npm run lint 2>&1); then |
| 2. **コミット前に `npm run lint` を実行**: 未使用変数、`<img>`→`<Image>`、`any`型などのlintエラーを後追い修正しない(hooks で自動実行される) | ||
| 3. **`children` をカスタムprop名に使わない**: Reactの予約prop名と衝突するため、`generations` や `childItems` など具体的な名前を使う | ||
| 4. **`any` 型禁止**: `SupabaseClient<Database>` 等の適切な型を使う。型が不明な場合は `unknown` を使い、型ガードで絞り込む | ||
| 5. **外部サービスの設定値は初回から環境変数で管理**: モデル名・APIエンドポイント等をハードコードせず、`.env.local` と `CLAUDE.md` の Environment Setup に記載する |
There was a problem hiding this comment.
環境変数を追加する際、他の開発者が設定を再現できるように .env.local.example ファイルも更新することが重要です。ルールにこの点を明記することで、手順の漏れを防ぐことができます。
| 5. **外部サービスの設定値は初回から環境変数で管理**: モデル名・APIエンドポイント等をハードコードせず、`.env.local` と `CLAUDE.md` の Environment Setup に記載する | |
| 5. **外部サービスの設定値は初回から環境変数で管理**: モデル名・APIエンドポイント等をハードコードせず、`.env.local`、`.env.local.example`、`CLAUDE.md` の Environment Setup に記載する |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3407c74f70
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # PreToolUse hook: git commit 前に npm run lint を自動実行する | ||
| # git commit を含む Bash コマンドのみを対象とする |
There was a problem hiding this comment.
| COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty') | ||
|
|
||
| # git commit で始まるコマンドのみを対象とする | ||
| if [[ ! "$COMMAND" =~ ^git\ commit ]]; then |
There was a problem hiding this comment.
Match git commit beyond command-start only
if [[ ! "$COMMAND" =~ ^git\ commit ]]; then は先頭一致しか判定しないため、cd /workspace/visual-echo && git commit -m ... や環境変数付き実行のように git commit が先頭に来ない Bash コマンドでは lint チェックが完全にスキップされます。コメント上は「git commit を含む Bash コマンド」を対象としているため、実運用で想定されるコミット経路に抜け道が残ります。
Useful? React with 👍 / 👎.
- pre-commit-lint.sh: INPUT中間変数を削除し、stdinから直接jqにパイプ - pre-commit-lint.sh: if ! パターンで終了コード判定を簡潔化 - pre-commit-lint.sh: git commit の正規表現を先頭一致から部分一致に変更 - code-quality.md: 環境変数ルールに .env.local.example を追記 - settings.json: プロジェクト共有のhook設定を追加(settings.local.json は未追跡) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
.claude/rules/code-quality.mdに追加git commit前にnpm run lintを自動実行する Claude Code hook を設定追加ルール
npm run lint実行(hookで自動化)childrenをカスタムprop名に使わないany型禁止レビュー指摘の修正
cd失敗時のexit 0→ 空チェック +exit 1でエラーを検知*"git commit"*部分一致 →^git commit正規表現で先頭一致に変更Test plan
.claude/rules/code-quality.mdがセッション開始時に読み込まれることを確認git commitを含む Bash コマンドで lint が実行されることを確認🤖 Generated with Claude Code