From f7ef26d45018a8dd9df8ce2f3788690cbb7c210e Mon Sep 17 00:00:00 2001 From: "bert.hausmans" Date: Tue, 5 May 2026 23:24:41 +0200 Subject: [PATCH] chore(claude): add pint and eslint PostToolUse hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit post-edit-pint.sh runs vendor/bin/pint --dirty from api/ after any .php edit. post-edit-eslint.sh runs pnpm eslint --fix inside the matching SPA dir for .vue/.ts/.tsx/.js files under apps/app/ or apps/portal/. Both exit 0 unconditionally — formatting failures must not block the agent. --- .claude/hooks/post-edit-eslint.sh | 29 +++++++++++++++++++++++++++++ .claude/hooks/post-edit-pint.sh | 17 +++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 .claude/hooks/post-edit-eslint.sh create mode 100755 .claude/hooks/post-edit-pint.sh diff --git a/.claude/hooks/post-edit-eslint.sh b/.claude/hooks/post-edit-eslint.sh new file mode 100755 index 00000000..2d3dc704 --- /dev/null +++ b/.claude/hooks/post-edit-eslint.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -euo pipefail + +input="$(cat)" +path="$(echo "$input" | jq -r '.tool_input.file_path // .tool_input.path // empty')" + +[ -z "$path" ] && exit 0 + +# Strip leading absolute prefix if present, so we match repo-relative paths. +rel="$path" +if [[ "$path" = /* ]]; then + rel="${path#$CLAUDE_PROJECT_DIR/}" +fi + +# Match apps/app/** or apps/portal/** for .vue/.ts/.tsx/.js files. +if ! echo "$rel" | grep -Eq '^apps/(app|portal)/.+\.(vue|ts|tsx|js)$'; then + exit 0 +fi + +# Extract SPA dir and the path relative to it. +spa="$(echo "$rel" | grep -oE '^apps/(app|portal)')" +inside="${rel#$spa/}" + +# SPA may not exist yet (apps/portal/ is planned but not present in tree). +[ -d "$CLAUDE_PROJECT_DIR/$spa" ] || exit 0 + +cd "$CLAUDE_PROJECT_DIR/$spa" 2>/dev/null || exit 0 +pnpm eslint --fix "$inside" >/dev/null 2>&1 || true +exit 0 diff --git a/.claude/hooks/post-edit-pint.sh b/.claude/hooks/post-edit-pint.sh new file mode 100755 index 00000000..eade3f73 --- /dev/null +++ b/.claude/hooks/post-edit-pint.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail + +input="$(cat)" +path="$(echo "$input" | jq -r '.tool_input.file_path // .tool_input.path // empty')" + +# No path or non-PHP — nothing to do. +[ -z "$path" ] && exit 0 +[[ "$path" != *.php ]] && exit 0 + +# Laravel app lives in api/. Pint binary is at api/vendor/bin/pint. +cd "$CLAUDE_PROJECT_DIR/api" 2>/dev/null || exit 0 +[ -x vendor/bin/pint ] || exit 0 + +# --dirty only formats files with git changes — fast even when called per-edit. +vendor/bin/pint --dirty >/dev/null 2>&1 || true +exit 0