Skip to content

feat: Add code quality rules and pre-commit lint hook#3

Merged
kwrkb merged 3 commits intomainfrom
fix/code-quality-rules-and-hooks
Feb 25, 2026
Merged

feat: Add code quality rules and pre-commit lint hook#3
kwrkb merged 3 commits intomainfrom
fix/code-quality-rules-and-hooks

Conversation

@kwrkb
Copy link
Copy Markdown
Owner

@kwrkb kwrkb commented Feb 25, 2026

Summary

  • git履歴分析から抽出した6つの再発防止ルールを .claude/rules/code-quality.md に追加
  • git commit 前に npm run lint を自動実行する Claude Code hook を設定
  • Gemini CLI による5軸レビュー指摘(Medium 1件、Low 1件)を修正済み

追加ルール

  1. DBスキーマ変更は依存箇所を同一コミットで更新
  2. コミット前に npm run lint 実行(hookで自動化)
  3. children をカスタムprop名に使わない
  4. any 型禁止
  5. 外部サービス設定値は初回から環境変数管理
  6. Server/Client重複ロジックは共通関数に抽出

レビュー指摘の修正

  • cd 失敗時の exit 0 → 空チェック + exit 1 でエラーを検知
  • *"git commit"* 部分一致 → ^git commit 正規表現で先頭一致に変更

Test plan

  • .claude/rules/code-quality.md がセッション開始時に読み込まれることを確認
  • git commit を含む Bash コマンドで lint が実行されることを確認
  • lint 失敗時にコミットがブロックされることを確認

🤖 Generated with Claude Code

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>
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @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

  • コード品質ルールの追加: Git履歴分析に基づき、6つのコード品質ルールを.claude/rules/code-quality.mdに追加しました。
  • プリコミットリンティングフックの導入: git commit前にnpm run lintを自動実行するClaude Codeフックを設定しました。
  • レビュー指摘の修正: Gemini CLIによるレビュー指摘(Medium 1件、Low 1件)を修正しました。

🧠 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
  • .claude/hooks/pre-commit-lint.sh
    • git commitコマンドの実行前にnpm run lintを自動的に実行するプリコミットフックを追加しました。
    • リンティングが失敗した場合にコミットをブロックし、エラーメッセージを表示するロジックを実装しました。
    • CLAUDE_PROJECT_DIRへのディレクトリ移動処理と、その設定が未定義の場合のエラーハンドリングを追加しました。
  • .claude/rules/code-quality.md
    • プロジェクトのコード品質を維持するための6つの具体的なルールを記述した新しいMarkdownファイルを追加しました。
    • DBスキーマ変更時の依存箇所更新、npm run lintの実行、childrenプロップ名の使用禁止、any型の禁止、外部サービス設定値の環境変数管理、Server/Client間の重複ロジック抽出に関するルールが含まれています。
Activity
  • Gemini CLIによる自動レビューで指摘されたMedium 1件、Low 1件の項目が修正されました。
  • 現在のところ、人間によるレビュー活動やコメントはありません。
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

レビュー結果ファイル(status/review.md)をgit管理対象外にする。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

このプルリクエストは、コード品質ルールを追加し、コミット前に自動でlintを実行するpre-commitフックを導入するもので、素晴らしい改善です。レビューコメントとして、フックスクリプトをより効率的で読みやすくするための提案を2点、また品質ルールをより完全なものにするための提案を1点挙げさせていただきました。具体的には、シェルスクリプト内で中間変数を減らすリファクタリングと、環境変数に関するルールに .env.local.example の更新を含めることを提案しています。

Comment thread .claude/hooks/pre-commit-lint.sh Outdated
Comment on lines +6 to +7
INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

標準入力を一度変数に格納してからjqに渡す代わりに、直接パイプすることでよりシンプルで効率的なコードになります。不要な中間変数とechoコマンドを削減できます。

Suggested change
INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
COMMAND=$(jq -r '.tool_input.command // empty')

Comment thread .claude/hooks/pre-commit-lint.sh Outdated
Comment on lines +19 to +22
LINT_OUTPUT=$(npm run lint 2>&1)
EXIT_CODE=$?

if [ $EXIT_CODE -ne 0 ]; then
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

npm run lint を実行し、その終了コードを別の変数に保存して if でチェックする代わりに、if の条件式で直接コマンドの成否を判定する方がより簡潔で一般的なシェルスクリプトの書き方です。if ! LINT_OUTPUT=$(...); then のように書くことで、コマンドが失敗した場合(終了コードが非ゼロ)にのみブロック内が実行され、同時に出力もキャプチャできます。

Suggested change
LINT_OUTPUT=$(npm run lint 2>&1)
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
if ! LINT_OUTPUT=$(npm run lint 2>&1); then

Comment thread .claude/rules/code-quality.md Outdated
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 に記載する
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

環境変数を追加する際、他の開発者が設定を再現できるように .env.local.example ファイルも更新することが重要です。ルールにこの点を明記することで、手順の漏れを防ぐことができます。

Suggested change
5. **外部サービスの設定値は初回から環境変数で管理**: モデル名・APIエンドポイント等をハードコードせず、`.env.local``CLAUDE.md` の Environment Setup に記載する
5. **外部サービスの設定値は初回から環境変数で管理**: モデル名・APIエンドポイント等をハードコードせず、`.env.local``.env.local.example``CLAUDE.md` の Environment Setup に記載する

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +3 to +4
# PreToolUse hook: git commit 前に npm run lint を自動実行する
# git commit を含む Bash コマンドのみを対象とする
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Register this hook in Claude settings

このコミットでは .claude/hooks/pre-commit-lint.sh だけが追加され、PreToolUse でこのスクリプトを呼ぶ hooks 設定(.claude/settings*.json 側)が含まれていないため、リポジトリ単体では git commit 前 lint の自動実行が有効化されません。結果として、ここで実装した deny ロジックが実行されず、lint 失敗コミットを防げない状態になります。

Useful? React with 👍 / 👎.

Comment thread .claude/hooks/pre-commit-lint.sh Outdated
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')

# git commit で始まるコマンドのみを対象とする
if [[ ! "$COMMAND" =~ ^git\ commit ]]; then
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 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>
@kwrkb kwrkb merged commit 25ae958 into main Feb 25, 2026
@kwrkb kwrkb deleted the fix/code-quality-rules-and-hooks branch February 25, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant