Skip to content

Chore/setup husky lint staged - #409

Open
A-one-tech wants to merge 2 commits into
XStreamRollz:mainfrom
A-one-tech:chore/setup-husky-lint-staged
Open

Chore/setup husky lint staged#409
A-one-tech wants to merge 2 commits into
XStreamRollz:mainfrom
A-one-tech:chore/setup-husky-lint-staged

Conversation

@A-one-tech

Copy link
Copy Markdown

#Closes
#385

Summary

Configures Husky v9 and lint-staged v17 to run ESLint and Prettier on staged files before every commit, and tsc --noEmit across all backend/SDK packages before every push. This closes the feedback-loop gap where formatting and lint violations were only caught after a full CI run.

Closes #


Problem

There was no pre-commit hook in the repository. Formatting violations and lint errors accumulated locally and were only surfaced after a 5-minute CI run, creating slow feedback loops and noisy PR diffs.


Changes

package.json

  • Added "prepare": "husky" — auto-installs hooks when any contributor runs npm install at the root.
  • Added husky@9.1.7 and lint-staged@17.0.8 to devDependencies.

.lintstagedrc.json (new)

Defines which tools run on which staged file types:

Pattern Commands
*.{ts,tsx,js,jsx,mjs,cjs} eslint --max-warnings=0 --no-warn-ignored, then prettier --write
*.{json,md,yml,yaml,css} prettier --write

.husky/pre-commit (new)

Runs npx lint-staged on every git commit. Only staged files are checked — clean and fast.

.husky/pre-push (new)

Runs tsc --noEmit in parallel across api/, xstreamroll-sdk/, and xstreamroll-processing/ on every git push. The app/ Next.js package is intentionally excluded — its TypeScript is validated by the Next.js build pipeline.

CONTRIBUTING.md

Added a new Pre-commit Hooks section covering:

  • How to install hooks after cloning (npm run prepare)
  • What each hook does (table)
  • How to skip in exceptional cases (--no-verify)
  • A reference to .lintstagedrc.json

Testing

Pre-commit hook (lint-staged)

The hook fired automatically on the commit for this PR and ran successfully:

✔ Backed up original state in git stash
✔ Hiding unstaged changes to partially staged files...
✔ Running tasks for staged files...
✔ Staging changes from tasks...
✔ Restoring unstaged changes...
✔ Cleaning up temporary files...
[chore/setup-husky-lint-staged ae3ebbd] chore: configure husky and lint-staged
 6 files changed, 640 insertions(+), 23 deletions(-)

Pre-push hook (tsc --noEmit)

The hook fired on git push and all three packages passed type-checking:

Running type-checks on all packages...
✅ Type-checks passed.

First-time install

npm run prepare runs husky cleanly with exit code 0 and sets up the .husky/_/husky.sh shim.


Checklist

  • husky and lint-staged configured at the root
  • Pre-commit: ESLint + Prettier on staged files only
  • Pre-push: tsc --noEmit on affected packages (api, sdk, processing)
  • CONTRIBUTING.md updated with npm run prepare setup instructions
  • Hooks verified locally (pre-commit and pre-push both fired on this PR's commit/push)
  • No existing tests broken
  • No CI changes required — hooks run locally only

@Xhristin3

Copy link
Copy Markdown
Contributor

@A-one-tech please fix the CI. Thanks.

Copy link
Copy Markdown
Contributor

Hey @A-one-tech, great initiative setting up Husky and lint-staged — this will definitely keep the codebase cleaner over time.

CI is failing on the bundle-analysis check (the quality check passes fine). The issue is the same pattern that comes up when Husky is first introduced: the root package.json prepare script calls husky, but in the CI environment Husky isn't installed before that script runs, so it exits with code 127.

A common fix is to make the prepare script CI-aware:

// package.json
"prepare": "is-ci || husky"

Or the simpler no-extra-dependency version:

"prepare": "husky || true"

Also worth noting: the CI runner is currently on Node 20, but one of the new dependencies (listr2@10.2.2) requires Node >=22.13.0 — you may want to bump the engine requirement or pin an older compatible version of that package.

Small tweaks, but once addressed this is ready to land!

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.

3 participants