setup-pre-commit by mattpocock/skills
npx skills add https://github.com/mattpocock/skills --skill setup-pre-commit检查是否存在 package-lock.json (npm)、pnpm-lock.yaml (pnpm)、yarn.lock (yarn)、bun.lockb (bun)。使用检测到的管理器。如果不明确,则默认使用 npm。
作为 devDependencies 安装:
husky lint-staged prettier
npx husky init
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
这将创建 .husky/ 目录,并在 package.json 中添加 prepare: "husky"。
.husky/pre-commit写入此文件(Husky v9+ 不需要 shebang):
npx lint-staged
npm run typecheck
npm run test
调整:将 npm 替换为检测到的包管理器。如果仓库的 package.json 中没有 typecheck 或 test 脚本,则省略这些行并告知用户。
.lintstagedrc{
"*": "prettier --ignore-unknown --write"
}
.prettierrc(如果缺失)仅在不存在 Prettier 配置时创建。使用以下默认值:
{
"useTabs": false,
"tabWidth": 2,
"printWidth": 80,
"singleQuote": false,
"trailingComma": "es5",
"semi": true,
"arrowParens": "always"
}
.husky/pre-commit 存在且可执行.lintstagedrc 存在prepare 脚本是 "husky"prettier 配置存在npx lint-staged 以验证其正常工作暂存所有已更改/创建的文件,并使用以下提交信息提交:Add pre-commit hooks (husky + lint-staged + prettier)
这将运行新的预提交钩子——这是验证一切正常工作的良好冒烟测试。
prettier --ignore-unknown 会跳过 Prettier 无法解析的文件(如图像等)每周安装量
750
代码仓库
GitHub 星标数
9.5K
首次出现
2026年2月13日
安全审计
安装于
opencode713
codex711
gemini-cli709
github-copilot705
kimi-cli703
cursor703
Check for package-lock.json (npm), pnpm-lock.yaml (pnpm), yarn.lock (yarn), bun.lockb (bun). Use whichever is present. Default to npm if unclear.
Install as devDependencies:
husky lint-staged prettier
npx husky init
This creates .husky/ dir and adds prepare: "husky" to package.json.
.husky/pre-commitWrite 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.
.lintstagedrc{
"*": "prettier --ignore-unknown --write"
}
.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"
}
.husky/pre-commit exists and is executable.lintstagedrc existsprepare script in package.json is "husky"prettier config existsnpx lint-staged to verify it worksStage all changed/created files and commit 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.
prettier --ignore-unknown skips files Prettier can't parse (images, etc.)Weekly Installs
750
Repository
GitHub Stars
9.5K
First Seen
Feb 13, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode713
codex711
gemini-cli709
github-copilot705
kimi-cli703
cursor703
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
136,300 周安装