Repository navigation
chore: add pre-commit/pre-push hooks that lint changed files - #47
Merged
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
preparescript installs husky onnpm install/npm ci, so a fresh clone gets the hooks with no manual step. It ishusky || trueso it can't break installs where husky isn't present (e.g. the package installed as a dependency).preparerather thanpostinstallbecause it is the lifecycle husky documents, and it doesn't fire for consumers' installs of a published tarball..husky/pre-commit:lint-stagedrunsscripts/lint-files.mjson the staged files, thennpm 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 skilldescriptionthat makes harnesses skip the skill), and merge conflict markers.--alllints every tracked file.scripts/check-hooks.mjs(npm run hooks:check, run bypretest): fails whencore.hooksPathisn't.husky/_or a hook file is missing, with the fix. Skipped in CI, withHUSKY=0, or without.git.npm ci(HUSKY=0) and runsnpm 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.mjscovers the linter;AGENTS.mddocuments the hooks.New dev dependencies:
husky,lint-staged,yaml(all pinned exactly).Verified
npm cisetscore.hooksPath=.husky/_and a commit with invalid JSON is blocked.description: Note: x), and a stale generatedplugin.json(via validate).hooks:checkfails whencore.hooksPathis pointed elsewhere.npm run checkpasses (144 shell checks, 51 node tests).Not changed
check-plugin-versionstays inpre-pushand CI rather thanpre-commit.