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 8 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: 12. 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

Before you start

Confirm the current directory is inside a git repository and that package.json exists. If either check fails, stop and tell the user before installing anything.

Tell the user that the prepare script runs on every install and the pre-commit hook runs on every commit for all contributors, and continue only with their agreement.

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 no lockfile or more than one lockfile is found, ask the user which package manager to use. Keep a single lockfile, and use the detected package manager's command forms in every later step, including in place of npx.

2. Install dependencies

Install as devDependencies:

husky lint-staged prettier

Use the detected package manager's command for adding dev dependencies. Confirm the install succeeded and that husky and lint-staged are now listed as local devDependencies before continuing; if not, stop and tell the user. Report the installed versions to the user, and keep the lockfile so the exact versions are recorded. If the installed Husky version does not match the Husky v9+ assumption below, stop and tell the user.

3. Initialize Husky

First check for an existing prepare script in package.json, a custom git hooks path, an existing .husky/ dir or .husky/pre-commit file, and any existing lint-staged configuration (a config file or a lint-staged key in package.json). If any exist, show the user what init would replace, keep the existing prepare command alongside husky, keep prior hook commands, and get the user's confirmation before continuing.

Run only the locally installed binary from step 2. If npx would need to download a package, stop and tell the user.

npx husky init

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

4. Create .husky/pre-commit

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. 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 contents of those scripts from package.json. The hook must run lint-staged from the local install only. If a .husky/pre-commit file already exists, keep its prior commands and add these lines after confirming with the user.

5. Create .lintstagedrc

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

If a lint-staged configuration already exists, add this rule to it after the user confirms instead of creating a second file. This pattern lets Prettier rewrite every staged file it can parse; tell the user, offer to narrow the pattern to the file types the repo uses, and make sure a Prettier ignore file excludes lockfiles, build output and vendored directories.

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 local install only and after telling the user it will reformat staged files

8. Commit

Check the working tree status first. Stage only the files this skill created or changed, by explicit path: package.json, the lockfile, .husky/pre-commit, .lintstagedrc, and .prettierrc if it was created. Leave any unrelated changes that already existed unstaged and tell the user about them. Show the staged diff, remind the user that the commit runs the typecheck and test scripts, and get the user's 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. If the hook fails, report the failing command and its output to the user and wait for their direction; keep the hooks active for the commit unless the user explicitly asks otherwise.

In the final summary, list the exact hook commands and explain that the hooks can be removed by deleting the .husky/ dir and the prepare script.

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.chainreg.biz/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.