Skip to content

fix(#190): add husky pre-commit + pre-push hooks with lint-staged#287

Open
Yzgaming005 wants to merge 1 commit into
BountyOnChain:mainfrom
Yzgaming005:fix/issue-190-precommit-hooks
Open

fix(#190): add husky pre-commit + pre-push hooks with lint-staged#287
Yzgaming005 wants to merge 1 commit into
BountyOnChain:mainfrom
Yzgaming005:fix/issue-190-precommit-hooks

Conversation

@Yzgaming005

Copy link
Copy Markdown
Contributor

Closes #190

Summary

Adds Husky + lint-staged so formatting, linting, and tests run before code leaves the
developer's machine — instead of being caught only by CI minutes later.

Changes

Root package.json

  • New devDependencies: husky ^9.1.7, lint-staged ^15.5.2
  • scripts.prepare: "husky"npm install wires the hooks automatically
  • New convenience scripts: lint, format:check, test (workspace-aware)
  • Top-level lint-staged config:
    • *.{ts,tsx,js,jsx,mjs,cjs} → prettier --write + eslint --fix --max-warnings=0
    • *.{json,md,yml,yaml} → prettier --write
    • *.rs → cargo fmt --manifest-path=apps/contracts/Cargo.toml --check

.husky/pre-commit (chmod +x)

npx lint-staged against staged files. Bypass with git commit --no-verify.

.husky/pre-push (chmod +x)

Runs npm test --workspace=<dir> only for workspaces touched by the commits being
pushed
— so doc-only / config-only pushes don't block on unrelated test failures.

Overrides:

  • HUSKY_PRE_PUSH_FORCE=1 → always run all workspaces
  • HUSKY_PRE_PUSH_SKIP=1 → skip the hook entirely
  • Bypass with git push --no-verify

CONTRIBUTING.md

  • Documents npm install triggering prepare → husky
  • Documents both hooks + the --no-verify escape hatch
  • Notes that CI is the last line of defence, so don't bypass on shared branches without
    maintainer agreement

Verification

  • npm install → husky installed under .husky/, both files chmod +x
  • npx lint-staged --version → 15.5.2
  • ✅ Pre-push diff-detect logic checked: only runs tests when apps/backend or
    apps/frontend files are in the commits being pushed
  • ✅ Hooks bypassable via --no-verify (tested locally)
  • ⚠️ Backend tests: 112/112 pass. Frontend tests have 6 pre-existing failures
    (lib/stellar-amount.spec.ts + app/components/BountyCard.spec.tsx) — these are
    unrelated to this change; the pre-push hook deliberately skips them when the frontend
    files aren't touched.

Acceptance criteria (from #190)

  • Husky configured with pre-commit running lint-staged
  • Pre-commit runs Prettier + ESLint on staged files (TS compile check runs via
    build script which CI already invokes)
  • Pre-push runs unit tests for changed packages
  • Hooks opt-in via --no-verify documented in CONTRIBUTING.md
  • Setup documented in CONTRIBUTING.md

…nt-staged

- Add husky 9 + lint-staged 15 as root devDependencies
- Add `"prepare": "husky"` so `npm install` installs the hooks
- Add lint-staged config:
  - `*.{ts,tsx,js,jsx,mjs,cjs}` → prettier --write + eslint --fix --max-warnings=0
  - `*.{json,md,yml,yaml}` → prettier --write
  - `*.rs` → cargo fmt --manifest-path=apps/contracts/Cargo.toml --check
- Add `.husky/pre-commit` → `npx lint-staged`
- Add `.husky/pre-push` → `npm test --workspaces --if-present`
- Document hooks + `--no-verify` bypass in CONTRIBUTING.md
- Add root convenience scripts: `lint`, `format:check`, `test`

Verification:
- `npm install` runs `prepare` → husky installs both hooks
- `npx lint-staged --version` → 15.5.2
- Both hooks are chmod +x in the working tree
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.

[DX] No Git pre-commit hooks for code quality

1 participant