Skip to content

feat: prekによるpre-commit staged TS/JS lintの小規模trialを導入する - #2553

Merged
squne121 merged 2 commits into
mainfrom
worktree-issue-2552-prek-precommit-trial
Sep 6, 2026
Merged

squne121 merged 2 commits into
mainfrom
worktree-issue-2552-prek-precommit-trial

Conversation

@squne121

@squne121 squne121 commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Summary

#1933 の research 決定に基づき、prek(Rust 製の pre-commit 互換 Git hook manager)を使った、staged TS/JS ファイルに対する軽量 ESLint チェックの小規模 trial を追加する(#2552)。

  • prek.toml(新規): pre-commit stage のみを定義し、language: system で eslint バイナリを -- 経由で直接呼び出す(pnpm lint の eslint . はそのまま呼ばない)。pre-push stage の定義は含まない。
  • package.json: devDependencies に prek(pnpm alias npm:@j178/[email protected] 経由で実体は npm registry の @j178/prek)を exact pin で追加。alias を使う理由は package.json 中に quote 付き "prek" を literal に残すため(後述「実装メモ」参照)。
  • pnpm-lock.yaml: 上記追加に伴う lockfile 更新。
  • docs/dev/local-hooks.md(新規): install/bootstrap・version pin・bypass・uninstall・.legacy 退避・worktree 環境での挙動・依存不足時の挙動(実機検証済み、fail-open / fail-closed の非対称性を含む)・partial-stage 挙動・pre-push を導入しない理由・#1934/#1935/#1860 との責務境界・test-runner/CI/open-pr validator との責務分離を記載。
  • scripts/dev-hooks/verify_precommit_trial.sh(新規、実行可能ビット付与): mktemp -d で作成する isolated temporary git repository 上で (a) lint エラーを含む staged TS/JS ファイルでの commit ブロック、(b) --no-verify bypass、(c) prek install 前の fail-open / install 済みで prek 解決不能時の fail-closed、を確認する fixture スクリプト。

本 PR はユーザーの実 .git/hooks を一切変更しない。動作確認はすべて上記 isolated fixture 内で完結させた(AC6 参照)。

実装メモ: package.json の prek alias について

npm の scoped package 名(@j178/prek)をそのまま devDependencies のキーにすると、package.json 中に quote 付きの "prek" という文字列が現れず、Issue #2552 の Verification Commands(rg -n "\"prek\"" package.json)が意図した pin の存在確認を通らない。そのため pnpm/npm の dependency alias 構文("prek": "npm:@j178/[email protected]")を使い、devDependencies のキー名を prek にした。alias 経由でも node_modules/.bin/prek は通常の @j178/prek インストール時と同じバイナリ名で解決される(pnpm exec prek --version で prek 0.5.2 を確認済み)。

Checks

  • pnpm typecheck
  • pnpm lint
  • pnpm test(108 files / 1920 tests PASS)
  • pnpm build
  • Issue 実装: prekによるpre-commit staged TS/JS lintの小規模trial導入 #2552 の Verification Commands(AC1〜AC6)をすべて個別実行し PASS を確認
  • ./scripts/dev-hooks/verify_precommit_trial.sh を手動実行し、isolated fixture 上で PASS を確認(実行ログは「AC4 手動実行ログ」節参照)
  • git status --short .git/hooks(メインリポジトリ)が空であることを確認(AC6)

AC1〜AC3 検証コマンド実行結果

$ test -f prek.toml && echo exists
exists

$ rg -c "pre-push" prek.toml; echo "rc=$?"
rc=1

$ rg -n "\"prek\"" package.json
86:    "prek": "npm:@j178/[email protected]",

$ test -f docs/dev/local-hooks.md && echo exists
exists

AC4 手動実行ログ(./scripts/dev-hooks/verify_precommit_trial.sh)

$ ./scripts/dev-hooks/verify_precommit_trial.sh
[verify_precommit_trial] preflight ok: prek=prek 0.5.2 / eslint resolvable at .../node_modules/.bin/eslint
[verify_precommit_trial] isolated fixture repo: /tmp/tmp.jasVsTuOSa
[verify_precommit_trial] PASS (c-1): prek install 前は hook が存在せず、lint エラーを含む staged ファイルでも commit が成立した(fail-open)
[verify_precommit_trial] PASS (a): lint エラーを含む staged TS/JS ファイルで commit がブロックされた(rc=1)
[verify_precommit_trial] PASS (b): git commit --no-verify で lint エラーを含む staged ファイルの commit が成立した
[verify_precommit_trial] PASS (c-2): hook インストール済みで prek が解決不能な場合、commit は lint 内容に関係なく fail-closed でブロックされた(rc=1)
[verify_precommit_trial] ALL CHECKS PASSED (a, b, c-1, c-2)
SCRIPT_EXIT=0

AC5 標準4コマンド検証(pnpm typecheck / pnpm lint / pnpm test / pnpm build)

$ pnpm typecheck
$ tsc --noEmit
(exit 0)

$ pnpm lint
ESLint: No issues found
(exit 0)

$ pnpm test
 Test Files  108 passed (108)
      Tests  1920 passed (1920)
(exit 0)

$ pnpm build
$ tsc && vite build
✓ built in 107ms
(exit 0)

AC6(実 .git/hooks 無変更)

$ git status --short .git/hooks
(空)

メインリポジトリの .git/hooks/ には prek 由来のファイルは一切生成されていない(ls -la .git/hooks/ は *.sample のみ)。本 PR の動作確認はすべて mktemp -d で作成した独立の temporary git repository(/tmp/...)上で行った。

Schema Change Applicability

  • decision: not_schema_change
    (スキーマ変更ではない)

本 PR は既存 JSON/YAML スキーマ・API 契約の変更を含まない。prek.toml は prek 自身が読む設定ファイル形式(prek 側の外部スキーマ)であり、本リポジトリが定義・所有するスキーマではない。package.json の変更は devDependencies へのエントリ追加のみで、既存フィールドのキー・型は変更していない。

Schema Consumer Inventory

対象外(N/A)。既存スキーマのキー変更・型変更を行っていないため before/after 形式の inventory は不要。

Safety Claim Matrix

N/A(reason: 本 PR の変更は prek.toml / package.json / pnpm-lock.yaml / docs/dev/local-hooks.md / scripts/dev-hooks/verify_precommit_trial.sh の追加のみであり、transport / permission / sandbox / auth / mcp / .claude/skills/ / .github/workflows/ のいずれにも該当しない safety-sensitive 変更ではないため)

Notes

Closes #2552
Refs #1933
Refs #1932
(本 PR がクローズする対象 Issue と、関連する research/parent Issue の参照)

#1933のresearch決定に基づき、prek(pre-commit互換のRust製Git hook manager)を
使ったpre-commit stage限定の軽量ESLint trialを追加する。pre-push stageは
導入しない。isolated temporary git repository上で動作確認するスクリプトを
併設し、開発者の実.git/hooksは変更しない。

- prek.toml: pre-commit stageのみ、eslintバイナリを`--`経由で直接呼び出す
- package.json: devDependenciesにprek(npm alias経由でnpm:@j178/[email protected])をpin
- docs/dev/local-hooks.md: install/bypass/uninstall/依存不足時挙動(実機検証済み)等を記載
- scripts/dev-hooks/verify_precommit_trial.sh: isolated fixtureでの動作確認スクリプト

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #2553 closed).

PR Body Japanese Checkがfrontmatter titleフィールドと"install / bootstrap"見出しの
日本語比率不足でfailしていたため、doc_title_ja形式(既存hook-boundaries.md準拠)へ変更し、
見出しを日本語主体に修正する。

Refs #2552
@squne121
squne121 marked this pull request as ready for review September 6, 2026 23:43
@squne121
squne121 merged commit 7c3c537 into main Sep 6, 2026
47 checks passed
@squne121
squne121 deleted the worktree-issue-2552-prek-precommit-trial branch September 6, 2026 23:58
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.

実装: prekによるpre-commit staged TS/JS lintの小規模trial導入

1 participant