Skip to content

feat(hooks): check stale comments at git commit and in Japanese - #253

Merged
paveg merged 3 commits into
mainfrom
feat/rot-comments-commit-gate
Oct 8, 2026
Merged

paveg merged 3 commits into
mainfrom
feat/rot-comments-commit-gate

Conversation

@paveg

@paveg paveg commented Oct 8, 2026

Copy link
Copy Markdown
Owner

概要

陳腐化するコードコメントを止める rot-comment hook が、実際には効いていない場面がありました。この PR で 2 つの原因を塞ぎ、ルールも合わせて補強します。

過去の transcript で、ユーザーが「不要なコードコメントは極力書かなくて良い」と指摘した箇所を調べると、直前に書かれていたコメントは次のようなものでした。

  • 他ファイルとの同期指示: 「この行と validate_owners.py の MIGRATION_OPS_TEAMS に足す」
  • 出所の記録: 「gh api … で取得した実値」
  • 3〜4 行にわたる経緯や ADR の要約

hook がこれらを素通りした原因は 2 つです。

  • 編集が Bash 内の Python スクリプト経由だった。hook は Write/Edit/MultiEdit にしか掛かっていないので、一度も発火していない
  • パターンが英語だけだった

変更内容

  • executable_block-rot-comments.py
    • git commit の実行時にも発火し、commit される diff(git diff --cached。-a/--all のときは git diff HEAD)に追加されたコメントを検査する。書き込み経路に関係なく捕まえられる
    • cd <dir> && と git -C <dir> に対応した。-m "-a" のような値を -a フラグと誤認しない
    • git が失敗したとき、タイムアウトしたとき、リポジトリ外のときは、commit を止めずに通す
    • 日本語パターンを追加した。誤検知の少ないものだけに絞っている
      • 時期の表現: 以前は/従来は/旧仕様/今回の変更・修正・対応
      • 呼び出し元の言及: ASCII の識別子に続く「から呼ばれ」
      • 同期指示: 〜と一致させる/〜にも足す/CONST に足す など
      • 出所: 〜で取得した値
  • settings.json.tmpl: Bash の PreToolUse にこの hook を登録した
  • development-principles.md: コメントは言語を問わず既定で 1 行にした。同期指示はテストやチェックで担保し、出所と経緯は commit メッセージ・PR・ADR に書く。hook が拾えるのは一部だけだとも明記した

差分の大半はテスト(tests/hooks/block-rot-comments.test.sh)です。

検証

  • just test → ✓ All checks passed!
  • TDD: 日本語パターンと、正当なコメントを通すケースのテストは、未改修の hook で Red になることを確認してから実装した
  • commit 時検査: 検査の分岐を無効化したコピーではテストが red(FAIL: commit gate did not block staged rot comment)になり、元に戻すと green になることを確認した
  • 誤検知: レビューで、通常の why コメントを止めてしまうパターンが 7 つ見つかった(例: 「複数スレッドから呼び出されるため、ロックが必要」)。それらを外し、正当なコメントが通ることを確かめるテストを 8 件追加した。外したパターン用の BLOCK テスト 9 件は削除した。9 件すべてが外したパターンに対応している
  • 未確認: chezmoi apply 後の実地での発火

🤖 Generated with Claude Code

paveg and others added 3 commits October 8, 2026 20:02
The rot-comment hook only saw Write/Edit/MultiEdit, so comments written
through Bash never reached it, and its patterns were English-only. Scan the
diff a Bash git commit will record, and add Japanese temporal, caller,
keep-in-sync and provenance patterns.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…mments

Drop the generic phrases (を追加した, 呼び出し元, で使われる, ...) that also
appear in legitimate constraint comments. Keep から呼ばれ only after an ASCII
identifier and match provenance only as で取得した(実)値.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… check

Comments are one line by default in any language. Keep-in-sync
instructions belong in a test or check; provenance and decision
history belong in the commit message, PR body, or ADR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a9b4506

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@paveg
paveg merged commit 607e93f into main Oct 8, 2026
12 checks passed
@paveg
paveg deleted the feat/rot-comments-commit-gate branch October 8, 2026 11:11
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