Files
InvoiceShelf/.githooks/pre-commit
Darko Gjorgjijoski f3ab0f22fc chore(frontend): fix ESLint, add Pint+ESLint pre-commit hook, centralize v-html
Fix the broken ESLint setup: add vue-eslint-parser and @typescript-eslint/parser
and wire the TS parser into eslint.config.mjs so .ts and <script lang=ts> parse
(was failing outright). Clear the resulting backlog to a clean 0/0 baseline —
fix genuine issues, relax two intentional-pattern rules (multi-word-component-names,
no-required-prop-with-default).

Add a committed .githooks/pre-commit (enabled via core.hooksPath, auto-set by the
prepare script) that runs Pint on staged PHP and ESLint --max-warnings 0 on staged
resources/scripts JS/TS/Vue, blocking on failure. Add composer/npm lint scripts and
document the gate in CLAUDE.md.

Replace every scattered v-html with a single audited BaseSanitizedHtml component
that DOMPurify-sanitizes its input (new utils/markdown.ts sanitizeHtml), so
server/registry-provided HTML is actually sanitized and vue/no-v-html stays enabled
everywhere but one reviewed sink.
2026-06-11 11:11:12 +02:00

37 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# Pre-commit gate: Laravel Pint (PHP) + ESLint (JS/TS/Vue) must be clean on staged files.
# See CLAUDE.md "Code Quality Gate". Bypass intentionally (discouraged): git commit --no-verify
status=0
# --- Pint on staged PHP ---
php_files=$(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.php$' || true)
if [ -n "$php_files" ]; then
echo "▶ Pint (pre-commit)…"
# shellcheck disable=SC2086
if command -v php >/dev/null 2>&1 && [ -f vendor/bin/pint ]; then
php vendor/bin/pint --test -- $php_files || status=1
else
echo "⚠ Pint unavailable — skipping (run: composer lint before pushing)." >&2
fi
fi
# --- ESLint on staged JS/TS/Vue under resources/scripts (ESLint's configured scope) ---
js_files=$(git diff --cached --name-only --diff-filter=ACMR | grep -E '^resources/scripts/.*\.(js|cjs|mjs|ts|vue)$' || true)
if [ -n "$js_files" ]; then
echo "▶ eslint (pre-commit)…"
# shellcheck disable=SC2086
if [ -x node_modules/.bin/eslint ]; then
node_modules/.bin/eslint --max-warnings 0 $js_files || status=1
else
echo "⚠ eslint unavailable — skipping (run: npm run lint before pushing)." >&2
fi
fi
if [ "$status" -ne 0 ]; then
echo "✖ Lint failed — fix it (composer lint:fix / npx eslint --fix), then re-commit." >&2
echo " To bypass intentionally: git commit --no-verify" >&2
exit 1
fi
exit 0