Skip to content

chore: add pre-commit/pre-push hooks that lint changed files - #47

Merged
glennfaison merged 1 commit into
mainfrom
chore/pre-commit-hooks
Oct 31, 2026
Merged

glennfaison merged 1 commit into
mainfrom
chore/pre-commit-hooks

Conversation

@glennfaison

Copy link
Copy Markdown
Owner

What

There were no git hooks in this repo: no husky, no core.hooksPath, no linter. Nothing could have been "ignored" because nothing was installed. This PR adds them and makes a missing install visible.

Changes

  • prepare script installs husky on npm install / npm ci, so a fresh clone gets the hooks with no manual step. It is husky || true so it can't break installs where husky isn't present (e.g. the package installed as a dependency). prepare rather than postinstall because it is the lifecycle husky documents, and it doesn't fire for consumers' installs of a published tarball.
  • .husky/pre-commit: lint-staged runs scripts/lint-files.mjs on the staged files, then npm run validate (package-wide rules, including the generated-files check).
  • .husky/pre-push: npm run check (lint, validate, plugin version, tests), i.e. everything CI runs.
  • scripts/lint-files.mjs: per-file lint for .mjs/.js (syntax), .sh (bash -n, plus shellcheck at error severity when installed), .json, .yml/.yaml, markdown front matter as strict YAML (catches the unquoted : in a skill description that makes harnesses skip the skill), and merge conflict markers. --all lints every tracked file.
  • scripts/check-hooks.mjs (npm run hooks:check, run by pretest): fails when core.hooksPath isn't .husky/_ or a hook file is missing, with the fix. Skipped in CI, with HUSKY=0, or without .git.
  • CI: installs with npm ci (HUSKY=0) and runs npm run lint. Client-side hooks can always be skipped (--no-verify, no install), so CI is the deterministic backstop and calls the same scripts.
  • tests/lint.test.mjs covers the linter; AGENTS.md documents the hooks.

New dev dependencies: husky, lint-staged, yaml (all pinned exactly).

Verified

  • Fresh clone + npm ci sets core.hooksPath=.husky/_ and a commit with invalid JSON is blocked.
  • Blocked at pre-commit: invalid JSON, broken skill front matter (description: Note: x), and a stale generated plugin.json (via validate).
  • hooks:check fails when core.hooksPath is pointed elsewhere.
  • npm run check passes (144 shell checks, 51 node tests).

Not changed

  • No changeset: dev tooling only, nothing user-visible.
  • check-plugin-version stays in pre-push and CI rather than pre-commit.
  • shellcheck is only enforced at error severity; the existing scripts have warnings (SC2034, SC1090) that I left alone.

- husky installs the hooks from the npm prepare script
- pre-commit: lint-staged runs scripts/lint-files.mjs on staged files, then npm run validate
- pre-push: npm run check (everything CI runs)
- hooks:check (run by pretest) fails when core.hooksPath or the hook files are not as installed
- CI installs with npm ci and runs npm run lint as the backstop for skipped hooks
@glennfaison
glennfaison merged commit e7d1d62 into main Oct 31, 2026
2 checks passed
@glennfaison
glennfaison deleted the chore/pre-commit-hooks branch October 31, 2026 20:10
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.

2 participants