
Security News
PolinRider: North Korea-Linked Supply Chain Campaign Expands Across Open Source Ecosystems
PolinRider expands across npm, Packagist, Go modules, and Chrome extensions, using hidden loaders to target developer environments.
@huaiyou/hooks-git
Advanced tools
Git 钩子配置,包含 Husky、Commitlint 和 Lint-staged,确保代码质量和提交规范。
pnpm add -D @huaiyou/hooks-git
注意:该包会自动处理所有依赖关系,无需手动安装 husky、@commitlint/cli 和 lint-staged。
使用以下命令一键完成所有配置:
npx hy-hooks-git init
该命令将自动:
如需自定义配置,可以使用交互式模式:
npx hy-hooks-git init --interactive
如果需要手动配置,可以按照以下步骤进行:
在项目根目录运行:
pnpm prepare
将以下文件复制到项目根目录:
commitlint.config.js:
module.exports = require('@huaiyou/hooks-git/commitlint');
lint-staged.config.js:
const { createLintStagedConfig } = require('@huaiyou/hooks-git/lint-staged');
module.exports = createLintStagedConfig();
创建 .husky/pre-commit:
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
pnpm lint-staged
创建 .husky/commit-msg:
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
pnpm commitlint --edit $1
在 package.json 中:
{
"scripts": {
"prepare": "husky install"
}
}
如果需要回滚所有配置,可以使用以下命令:
npx hy-hooks-git rollback
该命令将自动:
强制执行 Conventional Commits 规范:
在提交前自动运行代码检查和格式化:
<type>(<scope>): <subject>
<body>
<footer>
# 简单提交
feat: add user authentication
# 带作用域
feat(auth): implement JWT token validation
# 带详细描述
fix(api): resolve CORS issue in production
This fix addresses the CORS error that was preventing
requests from the frontend in production environment.
Closes #123
创建 commitlint.config.js:
const baseConfig = require('@huaiyou/hooks-git/commitlint');
module.exports = {
...baseConfig,
rules: {
...baseConfig.rules,
'subject-max-length': [2, 'always', 100], // 自定义主题长度
},
};
创建 lint-staged.config.js:
const { createLintStagedConfig } = require('@huaiyou/hooks-git/lint-staged');
// 获取基础配置
const baseConfig = createLintStagedConfig();
module.exports = {
...baseConfig,
'*.{ts,tsx}': [
'eslint --fix',
'prettier --write',
'vitest related --run', // 添加测试
],
};
或者直接扩展配置函数:
const { createLintStagedConfig } = require('@huaiyou/hooks-git/lint-staged');
module.exports = {
...createLintStagedConfig(),
'*.{ts,tsx}': [
'eslint --fix',
'prettier --write',
'vitest related --run', // 添加测试
],
};
# 跳过 pre-commit 钩子
git commit --no-verify
# 跳过 commit-msg 钩子
git commit -m "message" --no-verify
# 临时禁用 Husky
export HUSKY=0
# 提交
git commit -m "message"
# 重新启用
unset HUSKY
Closes #123 关联问题feat(api): change authentication method
BREAKING CHANGE: The old API key authentication is replaced
with JWT tokens. All clients must update to use the new
authentication method.
# 重新安装 Husky
rm -rf .husky
pnpm prepare
# 检查配置文件
cat commitlint.config.js
# 手动测试
echo "test: message" | pnpm commitlint
# 检查配置
cat lint-staged.config.js
# 手动运行
pnpm lint-staged
欢迎提交 Issue 和 Pull Request!
MIT
FAQs
Git hooks configuration with Husky, Commitlint and Lint-staged
The npm package @huaiyou/hooks-git receives a total of 41 weekly downloads. As such, @huaiyou/hooks-git popularity was classified as not popular.
We found that @huaiyou/hooks-git demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
PolinRider expands across npm, Packagist, Go modules, and Chrome extensions, using hidden loaders to target developer environments.

Security News
Open source attacks are accelerating as AI coding agents pull in dependencies faster, with less human review.

Research
/Security News
Malicious Chrome and Firefox extensions posed as free VPNs while stealing clipboard data through later extension updates.