Skip to content

chore(hooks): add precommit and push hooks (#186)#190

Open
natashaannn wants to merge 1 commit into
mainfrom
chore/hooks
Open

chore(hooks): add precommit and push hooks (#186)#190
natashaannn wants to merge 1 commit into
mainfrom
chore/hooks

Conversation

@natashaannn
Copy link
Copy Markdown

🚀 Summary

Adds Husky git hooks to catch AI coding mispractices and enforce quality gates before code enters the shared branch.

  • Pre-commit runs fast linting on staged files only (oxlint, oxfmt, golangci-lint)
  • Pre-push runs the full test suite and targeted static checks on files changed vs main

The pre-push hook specifically guards against patterns AI agents commonly produce: unsafe double casts (as unknown as), as any, lint/type suppression comments, and supply-chain risks from unreviewed packages.

✏️ Changes

  • .husky/pre-push: new hook with 8 checks — package safety (pnpm audit + new-dependency gate), gitleaks secret scanning, unsafe TS casts, lint/type suppression comments, tsc --noEmit, go test ./..., golangci-lint run, and frontend tests
  • Makefile: added gitleaks install target and make secrets BASE=... target; added Windows EXE suffix handling; updated make tools to install both golangci-lint and gitleaks
  • .lintstagedrc.js: added *.go entry that runs make lint (golangci-lint project-wide)
  • CONTRIBUTING.md: added ## Git Hooks section documenting both hooks, all 8 pre-push checks with triggers, and per-check SKIP_* override env vars
  • .env.example: added commented-out SKIP_* override vars with descriptions
  • scripts/test-pre-push.sh: 32-assertion integration test covering all 8 checks, scoping logic, and all override env vars

🧪 Test Plan

  • bash scripts/test-pre-push.sh — 32/32 assertions pass, 0 failed, 0 skipped
  • Manually verified each check blocks as expected:
    • Push with new package.json entry → blocked by check 1, lists packages and review checklist
    • SKIP_PKG_CHECK=1 git push → passes with warning and checklist reminder
    • Push with AKIA1234567890ABCDEF in diff → blocked by gitleaks (check 2)
    • Push with as unknown as Foo in source TS → blocked by check 3
    • Push with // oxlint-disable in TS → blocked by check 4
    • Push with @ts-expect-error in *.test.ts only → passes check 4
    • Push with failing Go test → blocked by check 6
    • Push with no Go or TS changes → all checks skip cleanly, no output noise
    • git push --no-verify → bypasses all checks (standard git behaviour)

Issues Closes #186

Eight checks run on branch-changed files vs main: package safety (pnpm audit +
manual review gate on new dependencies), secret scanning (gitleaks v8.27.2),
unsafe TypeScript casts (`as any`, `as unknown as X` in source files), lint and
type suppression comments (`eslint-disable`, `oxlint-disable`, `@ts-ignore`,
`@ts-nocheck`, `@ts-expect-error` outside test files), `tsc --noEmit`, `go test
./...`, `golangci-lint run`, and `pnpm test` (gated on `vitest.config.ts`).

Each check has a `SKIP_*` env var override that prints a warning and requires
justification in the PR description. `git push --no-verify` bypasses all checks.

Also: gitleaks added to Makefile `tools` target; `lint-staged` extended with
`*.go: make lint`; Git Hooks section added to CONTRIBUTING.md with full check
table and override reference; `SKIP_*` vars documented as comments in
`.env.example`; test harness at `scripts/test-pre-push.sh` (32 assertions,
all passing).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@natashaannn natashaannn requested a review from nicholasjjlim May 22, 2026 10:16
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.

Setup precommit and prepush hooks

1 participant