56 results available
Sign in
Skills directory

setup-pre-commit

mattpocock

·

Last changed
Hardened

This skill has been hardened by Chainguard

Last changed

This version passed the hardening gate. Hardening applied 9 targeted changes and preserved all other text. Classified findings before hardening: 1. Classified findings closed: 0. Classified findings remaining: 1. Unclassified scanner findings remaining: 0. Review findings closed: 11. Review findings remaining: 1.


Open before hardening

1

Medium
Open after hardening

1

Medium

Expand
File
Group
Subtype
Severity
Status
SKILL.md

Supply Chain & Install-Time Trust

—

Medium
Open

1 finding


SKILL.md

Setup Pre-Commit Hooks

What This Sets Up

  • Husky pre-commit hook
  • lint-staged running Prettier on all staged files
  • Prettier config (if missing)
  • typecheck and test scripts in the pre-commit hook

Steps

1. Detect package manager

Check for package-lock.json (npm), pnpm-lock.yaml (pnpm), yarn.lock (yarn), bun.lockb (bun). Use whichever is present. If several lockfiles or none are found, ask the user which package manager to use. Before installing, check the repo's package manager config files for a custom registry and report any you find to the user.

2. Install dependencies

Install as devDependencies:

husky lint-staged prettier

Use the detected package manager's dev dependency option. Husky must be version nine or later, since later steps rely on that behavior. Keep the updated lockfile and include it in the commit so later installs resolve the same versions. Tell the user these packages come from the registry at their current versions so they can review them.

3. Initialize Husky

npx husky init

This creates .husky/ dir and adds prepare: "husky" to package.json.

Before running it, check package.json for an existing prepare script and check for an existing .husky/pre-commit. Tell the user this adds a prepare script and a committed hook that run for every contributor, and get confirmation first. If a prepare script already exists, keep it and run husky after it. Run npx husky init only after step 2 has installed Husky locally; if the local package is missing, stop and tell the user so that npx uses the project copy only.

4. Create .husky/pre-commit

If .husky/pre-commit already exists, merge these lines into it or ask the user before replacing it. Otherwise write this file (no shebang needed for Husky v9+):

npx lint-staged
npm run typecheck
npm run test

Adapt: Replace npm with detected package manager. Replace npx with the detected package manager's command for running a locally installed binary, so the hook uses only the project copy. If repo has no typecheck or test script in package.json, omit those lines and tell the user. Before adding the typecheck and test lines, show the user the exact script contents from package.json and get confirmation.

5. Create .lintstagedrc

If a lint-staged config already exists (including a lint-staged key in package.json), merge into it or ask the user before replacing it.

{
  "*": "prettier --ignore-unknown --write"
}

Tell the user this hook rewrites every staged file Prettier understands in place on each commit, and suggest a Prettier ignore file for generated or vendored content if the repo has any.

6. Create .prettierrc (if missing)

Only create if no Prettier config exists. Use these defaults:

{
  "useTabs": false,
  "tabWidth": 2,
  "printWidth": 80,
  "singleQuote": false,
  "trailingComma": "es5",
  "semi": true,
  "arrowParens": "always"
}

7. Verify

  • .husky/pre-commit exists and is executable
  • .lintstagedrc exists
  • prepare script in package.json is "husky"
  • prettier config exists
  • Run npx lint-staged to verify it works, using the locally installed copy; if it is missing, stop and tell the user

8. Commit

Stage only the files this skill changed or created (package.json, the lockfile, .husky/pre-commit, .lintstagedrc, and .prettierrc if created). Leave other pre-existing changes unstaged unless the user approves. Show the user the git status and the staged diff, and ask for confirmation before committing with message: Add pre-commit hooks (husky + lint-staged + prettier)

This will run through the new pre-commit hooks: a good smoke test that everything works. Make this commit only after the user has approved running the typecheck and test scripts. If the hook fails, report the failure output to the user and let the user decide the next step; keep the hooks active and leave code and tests as they are.

Notes

  • Husky v9+ doesn't need shebangs in hook files
  • prettier --ignore-unknown skips files Prettier can't parse (images, etc.)
  • The pre-commit runs lint-staged first (fast, staged-only), then full typecheck and tests

Install

Install with chainctl
chainctl skill install public/mattpocock/setup-pre-commit:latest
Get started with chainctl
View source

Harden your own skills

Bring Chainguard's hardening pipeline to your first-party skills — custom rulesets, automated remediation, full audit trail.

Provenance

Upstream sourcehttps://github.com/mattpocock/skills
Upstream commit1bb95954ef0d06ba4d64a9c267fb75f57c614a1f
OCI reference

skills.cgr.dev/public/github.com/mattpocock/skills/misc/setup-pre-commit:latest

License

MIT

Files

HARDENING.md

LICENSE

SKILL.md

agents/openai.yaml


The trusted source for open source

Talk to an expert
PrivacyTerms

Product

Chainguard ContainersChainguard LibrariesChainguard VMsChainguard OS PackagesChainguard ActionsChainguard Agent SkillsIntegrationsPricing
© 2026 Chainguard, Inc. All Rights Reserved.
Chainguard® and the Chainguard logo are registered trademarks of Chainguard, Inc. in the United States and/or other countries.
The other respective trademarks mentioned on this page are owned by the respective companies and use of them does not imply any affiliation or endorsement.