Skip to content

examples/git-hooks: the pre-commit hook lints and format-checks the whole repo on every commit; scope it to the staged packages #401

Closed

Description

@Shinrai

Problem

examples/git-hooks/pre-commit runs npm run lint --if-present and npm run format:check --if-present unconditionally. In a single-package repo that is a few seconds. In a workspace whose lint script fans out to every package (scopra's is lint:backend && lint:frontend && lint:modules, about 60 packages), each commit pays the full sweep: about four minutes per commit on a loaded box, so a 13-commit path-scoped landing on 2026-10-26 spent close to an hour inside the hook. The hook is also check-only, so none of that time produces a fix.

Proposal

Keep the hook check-only and keep its fallback behaviour, but let it scope to what is being committed:

  1. The hook computes the staged file list with git diff --cached --name-only --diff-filter=ACMR.
  2. If the repo defines lint:staged and/or format:check:staged scripts, the hook calls those with the staged paths as arguments (npm run lint:staged --if-present -- <paths>), so the repo decides how to map files to packages (a workspace repo can map each path to its owning package and run that package's own scripts, which is the model where every package carries its own configs and scripts).
  3. If those scripts are absent, today's behaviour stays: lint and format:check over the whole repo.
  4. precommit:local stays last and unchanged.

docs/conventions/lint-format-precommit.md would document the two optional scripts. The post-merge CI autofix job is unaffected; it still runs the full sweep on next.

Why not lint-staged

A dependency on lint-staged changes the install footprint of every onboarded repo and moves the file-to-tool mapping into another config file. Two optional npm scripts keep the hook a thin shell and leave the mapping in the repo's own scripts, which is where the per-package tooling already lives.

Acceptance

  • A commit touching files in one workspace package runs only that package's lint and format check.
  • A repo without the staged scripts behaves exactly as today.
  • The hook is still check-only and never re-stages.
  • Reference consumer updated and the convention doc carries the new scripts.

Activity

  1. added
    type: enhancement
    priority: medium
    area: cli
    status: not started
    status: in progress
    and removed
    status: not started
    on Oct 30, 2026
  2. Shinrai commented on Nov 1, 2026

    @Shinrai
    ContributorAuthor

    #414 adds optional lint:staged / format:check:staged scripts. When a repo defines them, the hook passes the staged paths to them. Without them it falls back to the whole-repo lint / format:check. It stays check-only. The convention doc has an example. Reference consumers still need the scripts added; that happens per repo after this ships.

  3. added
    status: implemented
    and removed
    status: in progress
    on Nov 1, 2026
  4. cldmv-bot commented on Nov 1, 2026

    @cldmv-bot
    Contributor

    Marked status: implemented — resolved by #414, merged into next. This issue closes automatically when that work ships to the default branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: clipriority: mediumstatus: implementedtype: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions