0.0.1 • Published 4 months ago
commitlint-plugin-prime v0.0.1
commitlint-plugin-prime
一个用于强制执行自定义 scope 规则的 commitlint 插件。主要用于规范化提交信息中的 scope 格式,确保其符合 f-xxx
或 m-xxx
的规范。
特性
- ✨ 强制 feat 和 fix 类型提交必须包含 scope
- 🎯 确保 scope 符合规范格式 (f-xxx 或 m-xxx)
- 🔄 支持其他类型提交的可选 scope
- 📦 零依赖
- 🚀 支持 ESM 和 CommonJS
安装
npm install --save-dev commitlint-plugin-prime
# 或
yarn add -D commitlint-plugin-prime
# 或
pnpm add -D commitlint-plugin-prime
配置
- 在你的 commitlint 配置文件中添加以下内容:
// commitlint.config.js
module.exports = {
plugins: ["prime"],
rules: {
"custom-scope-rule": [2, "always"],
},
};
- 如果你使用的是 TypeScript,可以这样配置:
// commitlint.config.ts
import type { UserConfig } from "@commitlint/types";
const config: UserConfig = {
plugins: ["prime"],
rules: {
"custom-scope-rule": [2, "always"],
},
};
export default config;
规则说明
该插件实现了以下规则:
对于
feat
和fix
类型的提交:- 必须包含 scope
- scope 必须符合
f-xxx
或m-xxx
的格式 - f-xxx 通常用于前端相关改动
- m-xxx 通常用于后端(main)相关改动
对于其他类型的提交:
- scope 可选
- 如果包含 scope,必须符合
f-xxx
或m-xxx
的格式
示例
✅ 有效的提交信息:
# 前端功能开发
feat(f-login): 添加登录功能
feat(f-ui): 优化按钮样式
# 后端功能修复
fix(m-utils): 修复工具函数
fix(m-api): 修复接口响应格式
# 其他类型
chore: 更新依赖
docs(f-readme): 更新文档
style(m-code): 格式化代码
❌ 无效的提交信息:
# 缺少必需的 scope
feat: 添加登录功能
fix: 修复 bug
# scope 格式错误
feat(login): 添加登录功能
fix(utils): 修复工具函数
chore(xxx): 更新依赖
本地开发
# 克隆项目
git clone https://github.com/your-username/commitlint-plugin-prime.git
# 安装依赖
npm install
# 运行测试
npm test
# 构建
npm run build
# 本地测试
npm link
License
MIT
0.0.1
4 months ago