From ab7626d5f787a06f53118bc9a61e9cbfec514e6b Mon Sep 17 00:00:00 2001 From: Noel Sabia Date: Sun, 18 Oct 2026 18:15:44 +0200 Subject: [PATCH 1/2] chore: add pre-commit guardrails - gitleaks: block secrets before they enter history - pre-commit-hooks: whitespace/eof hygiene, yaml/json/toml checks, merge-conflict markers, large files, private keys - commitizen (commit-msg stage): enforce conventional commits so release-please always sees releaseable messages - actionlint: validate workflow files offline - eslint --fix on staged files (local hook, needs pnpm install) --- .pre-commit-config.yaml | 74 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..958fb03 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,74 @@ +# Pre-commit guardrails — deterministic checks that run before every commit. +# Cheap things live here (seconds); slow things (typecheck, build, tests, +# Snyk, AI review) stay in CI (.gitea/workflows/pr-checker.yml). +# +# One-time setup per machine: +# pre-commit install # pre-commit stage +# pre-commit install --hook-type commit-msg # commit-msg stage (release-please!) +# pre-commit run --all-files # first full pass +# +# ARM64 + x86_64 both supported by every hook below. + +repos: + # ---------------------------------------------------------------- gitleaks + # Block secrets before they enter history. CI scans history too (gitleaks + # job), but this prevents the commit from ever existing. + - repo: https://github.com/gitleaks/gitleaks + rev: v8.30.1 + hooks: + - id: gitleaks + + # -------------------------------------------------- basic file hygiene --- + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: mixed-line-ending + args: [--fix=lf] + - id: check-yaml + - id: check-json + - id: check-toml + - id: check-merge-conflict + - id: check-added-large-files + args: [--maxkb=1024] + - id: detect-private-key + + # ------------------------------------------------ conventional commits --- + # release-please silently ignores non-conventional messages, so a bad + # subject line means "no release and no idea why". This makes it + # impossible. Runs on the commit-msg stage, not pre-commit. + - repo: https://github.com/commitizen-tools/commitizen + rev: v4.19.2 + hooks: + - id: commitizen + stages: [commit-msg] + + # ---------------------------------------------------- workflow linting --- + # Validates .gitea/workflows syntax and ${{ }} expressions - the class of + # bug that hashFiles-skipping and broken YAML came from. + - repo: https://github.com/rhysd/actionlint + rev: v1.7.12 + hooks: + - id: actionlint + files: \.gitea/workflows/.*\.ya?ml$ + + # --------------------------------------------------------- ESLint (Nuxt) - + # Local hook: needs `pnpm install` to have run in this repo. --fix makes + # it a helper; only staged files are linted (fast). + - repo: local + hooks: + - id: eslint + name: eslint --fix (staged files) + entry: bash -c 'pnpm exec eslint --fix' + language: system + files: \.(vue|ts|js|mjs|cjs)$ + types: [file] + +# When Go services arrive, add: +# - repo: https://github.com/dnephin/pre-commit-golang +# rev: +# hooks: +# - id: go-fmt +# - id: go-imports +# - id: golangci-lint # or go-vet for a lighter pass -- 2.54.0 From 81d658a87105434835016ae20b24ef3cb7617d86 Mon Sep 17 00:00:00 2001 From: Noel Sabia Date: Sun, 18 Oct 2026 19:25:06 +0200 Subject: [PATCH 2/2] fix: pass staged filenames to the eslint pre-commit hook Validated from review comment 82 on this PR: the 'bash -c' wrapper consumed the first staged filename as $0 and the command never referenced $@, so eslint received zero file arguments and linted the whole repo - --fix silently rewrote unstaged files and WIP lint errors blocked unrelated commits. The entry now receives filenames directly from pre-commit (empirically verified with an arg probe); documented the re-stage loop for --fix and dropped the redundant 'types: [file]' filter. --- .pre-commit-config.yaml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 958fb03..a38845b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -55,15 +55,22 @@ repos: # --------------------------------------------------------- ESLint (Nuxt) - # Local hook: needs `pnpm install` to have run in this repo. --fix makes - # it a helper; only staged files are linted (fast). + # it a helper; only staged files are linted (fast). When --fix rewrites + # a staged file, pre-commit aborts the commit ("files were modified") - + # re-stage and commit again; that re-stage loop is the standard price + # of a fixer hook. - repo: local hooks: - id: eslint name: eslint --fix (staged files) - entry: bash -c 'pnpm exec eslint --fix' + # no shell wrapper: pre-commit appends the staged filenames to the + # entry itself. A 'bash -c' wrapper would eat the first filename + # as $0 and eslint would get no file arguments at all (linting the + # whole repo instead - review finding on this PR, empirically + # verified). + entry: pnpm exec eslint --fix language: system files: \.(vue|ts|js|mjs|cjs)$ - types: [file] # When Go services arrive, add: # - repo: https://github.com/dnephin/pre-commit-golang -- 2.54.0