Skip to content

feat: add lightweight staged-file pre-commit gates#59

Merged
Sparkier merged 1 commit into
mainfrom
jules/setup-pre-commit-gates-js1-6c0b599d-d670-4220-832c-f151a46e7d27
Jul 18, 2026
Merged

feat: add lightweight staged-file pre-commit gates#59
Sparkier merged 1 commit into
mainfrom
jules/setup-pre-commit-gates-js1-6c0b599d-d670-4220-832c-f151a46e7d27

Conversation

@google-labs-jules

Copy link
Copy Markdown
Contributor

Context & Rationale

Currently, developers can push poorly formatted or style-violating code to remote branches. This shifts the burden of formatting and basic lint checks entirely onto the late-stage CI pipeline, resulting in slower feedback loops and wasted CI resources.

To solve this, we are introducing a lightweight, local pre-commit gate system. By shifting these checks "left" into the local development workflow, we validate compliance before the code ever leaves the developer's machine.

Key Decisions

  • Staged-File Targeting: To keep the pre-commit gate fast (under the 3-second target) and avoid forcing developers to refactor untouched legacy code, we use lint-staged. This ensures only newly modified files are validated.
  • Tooling Exclusions: We have explicitly excluded full-workspace type-checking and unit-testing from this pre-commit hook to maintain high developer velocity and avoid sluggish commit operations.
  • Bun Integration: In alignment with our workspace toolchain, all package scripts and hook initializations are managed via bun.

Proposed Changes

  1. Dependency Additions

    • Added husky and lint-staged as development dependencies to orchestrate the Git hook lifecycle.
  2. Husky Hook Configuration

    • Added a "prepare": "husky" script in package.json so that Git hooks are automatically registered on developers' local machines upon running bun install.
    • Created a .husky/pre-commit hook that triggers bun x lint-staged whenever a commit is initiated.
  3. Staged Validation Configuration

    • Configured lint-staged within package.json to handle staged files:
      • Prettier (prettier --write): Automatically reformats and re-stages files with minor stylistic issues without halting the commit.
      • ESLint (eslint): Scans for code quality violations. If errors are found, the commit is aborted, and the offending lines are outputted directly to the terminal for local remediation.

Verification & Testing

  • Successful Commit: Verified that committing fully compliant files passes checks in under 2 seconds.
  • Auto-formatting: Verified that committing poorly formatted files triggers Prettier, auto-formats them, re-stages them, and successfully completes the commit.
  • Lint Failure Block: Verified that committing files with ESLint errors halts the commit and prints error details.
  • Bypassability: Verified that hooks can be safely bypassed when emergency overrides are needed using git commit --no-verify.

@Sparkier
Sparkier merged commit 378939d into main Jul 18, 2026
1 check passed
@Sparkier
Sparkier deleted the jules/setup-pre-commit-gates-js1-6c0b599d-d670-4220-832c-f151a46e7d27 branch July 18, 2026 09:36
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.

1 participant