Gitフック生成
pre-commit、pre-pushなどのGitフックスクリプトを生成します。
フック管理ツール
パッケージマネージャー
Gitフックステージ
Pre-commitチェック
pre-commit
# Block accidental commit of .env secrets
if git diff --cached --name-only | grep -qE "(^|/)\.env($|\.)" && ! git diff --cached --name-only | grep -qE "\.env\.example$"; then
echo "Error: Refusing to commit .env secret file. Unstage it first." >&2
exit 1
fi
npx --no -- lint-staged
npm run typecheck
セットアップ手順
npx --no -- husky init # Save script into .husky/pre-commit
関連設定ファイル
{
"lint-staged": {
"*.{ts,tsx,js,jsx}": [
"eslint --fix",
"prettier --write"
],
"*.{json,md,css}": [
"prettier --write"
]
}
}