@be-link/commitlint-config
v1.0.3
Published
共比邻 commitlint 共享配置
Downloads
76
Readme
📝 @be-link/commitlint-config
团队 Commitlint 共享配置,基于
@commitlint/config-conventional
💡 设计理念
本包是一个纯配置包,专注于提供 commit 规则配置,不负责依赖版本管理。
职责定位:
- ✅ 只提供 commitlint 规则配置
- ✅ 基于业界标准扩展定制
- ❌ 不管理依赖版本(使用 peerDependencies)
依赖管理由谁负责?
版本管理由@be-link/be-link-husky统一处理,它会根据 Node 版本自动安装匹配的依赖。
📦 安装
方式一:使用 @be-link/be-link-husky(推荐✨)
# 自动安装所有依赖并配置
pnpm install @be-link/be-link-husky -D这种方式会:
- ✅ 自动安装本配置包
- ✅ 自动安装 @commitlint/cli 和 @commitlint/config-conventional
- ✅ 根据 Node 版本选择合适的依赖版本
- ✅ 自动创建配置文件
方式二:手动安装
# 需要手动安装所有 peer dependencies
pnpm install @be-link/commitlint-config @commitlint/cli @commitlint/config-conventional -D然后在项目根目录创建 commitlint.config.js:
module.exports = {
extends: ['@be-link/commitlint-config'],
};📋 规则说明
支持的 Commit 类型
| Type | 说明 | 示例 |
| ---------- | --------- | -------------------------------- |
| feat | 新功能 | feat(user): 添加用户登录功能 |
| fix | 修复 Bug | fix(auth): 修复 token 过期问题 |
| docs | 文档变更 | docs: 更新 README |
| style | 代码格式 | style: 统一代码缩进 |
| refactor | 重构 | refactor(api): 优化接口结构 |
| perf | 性能优化 | perf: 优化列表渲染 |
| test | 测试相关 | test: 添加用户模块测试 |
| chore | 构建/工具 | chore: 升级依赖版本 |
Commit 消息格式
<type>(<scope>): <subject>
<body>
<footer>完整示例
feat(user): 添加用户登录功能
实现了用户登录的基本流程,包括:
- 用户名密码验证
- Token 生成和存储
- 登录状态管理
Closes #123简单示例
git commit -m "feat(user): 添加用户登录功能"
git commit -m "fix(cart): 修复购物车计算错误"
git commit -m "docs: 更新安装文档"规则特性
与官方 @commitlint/config-conventional 的差异:
| 规则 | 官方配置 | 本配置 | 说明 |
| ---------------------- | ----------------- | ------ | -------------- |
| header-max-length | 100 | 200 | 支持更长的标题 |
| body-max-line-length | 100 | 200 | 支持更长的正文 |
| subject-case | 限制 | 禁用 | 允许中文 |
| type-enum | 包含 build、ci 等 | 简化 | 只保留常用类型 |
🏗️ 架构设计
@be-link/be-link-husky (版本管理器)
↓ 自动安装
┌──────────────────────────────────────────┐
│ @commitlint/cli │ ← 校验工具
│ @commitlint/config-conventional │ ← 官方标准配置
│ @be-link/commitlint-config (本包) │ ← 团队定制规则
└──────────────────────────────────────────┘
↑ extends
官方标准依赖关系:
{
"peerDependencies": {
"@commitlint/cli": ">=17.0.0",
"@commitlint/config-conventional": ">=17.0.0"
}
}本包通过 peerDependencies 声明依赖,但不自动安装。由 @be-link/be-link-husky 负责版本选择和安装。
🔧 自定义配置
如果需要在项目中进一步定制规则:
// commitlint.config.js
module.exports = {
extends: ['@be-link/commitlint-config'],
rules: {
// 覆盖或新增规则
'header-max-length': [2, 'always', 100],
'scope-enum': [2, 'always', ['user', 'cart', 'order']],
},
};📚 更多信息
- 官方文档:commitlint.js.org
- 自动化工具:@be-link/be-link-husky
- Conventional Commits:conventionalcommits.org
📄 License
MIT
