fix:添加代码的git提交规范

This commit is contained in:
2026-01-10 21:23:50 +08:00
parent a69a19ca49
commit ca15400d3d
6 changed files with 1084 additions and 1 deletions

3
.husky/commit-msg Normal file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env sh
npx --no-install commitlint --edit "$1"

3
.husky/pre-commit Normal file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env sh
npx lint-staged

101
commitlint.config.cjs Normal file
View File

@@ -0,0 +1,101 @@
module.exports = {
// 继承通用提交规范规则
extends: ['@commitlint/config-conventional'],
// 自定义提交校验规则
rules: {
// 强制提交类型必须是以下列表中的值
'type-enum': [
2, // 2 = 必须符合不满足则报错1 = 警告0 = 关闭规则
'always',
[
'feat', // 新增功能
'fix', // 修复缺陷
'docs', // 文档变更(如 README 修改)
'style', // 代码格式调整(不影响功能,如空格、分号)
'refactor', // 代码重构既不是新增功能也不是修复bug
'perf', // 性能优化
'test', // 新增/修改测试用例
'build', // 构建流程/外部依赖变更(如 npm 包升级、webpack 配置修改)
'ci', // CI 配置/脚本修改
'revert', // 回滚之前的提交
'chore' // 辅助工具/构建过程变更(不影响源码和测试)
]
],
'subject-case': [0], // 不校验提交描述subject的大小写
'scope-empty': [2, 'never'] // 强制必须填写模块范围scope不允许空
},
// 交互式提交配置(配合 cz-git 使用,优化提交体验)
prompt: {
messages: {
type: '选择你要提交的类型 :',
scope: '选择一个提交范围(模块):',
customScope: '请输入自定义的模块名称 :',
subject: '填写简短精炼的变更描述 :\n',
body: '填写更加详细的变更描述(可选)。使用 "|" 换行 :\n',
breaking: '列举非兼容性重大的变更(可选)。使用 "|" 换行 :\n',
footerPrefixesSelect: '选择关联issue前缀可选:',
customFooterPrefix: '输入自定义issue前缀 :',
footer: '列举关联issue (可选) 例如: #31, #I3244 :\n',
generatingByAI: '正在通过 AI 生成你的提交简短描述...',
generatedSelectByAI: '选择一个 AI 生成的简短描述:',
confirmCommit: '是否提交或修改commit ?'
},
// 提交类型选项(用直观的 Emoji 字符,避免 Windows 解析失败)
types: [
{ value: 'feat', name: '特性: ✨ 新增功能', emoji: '✨' },
{ value: 'fix', name: '修复: 🐛 修复缺陷', emoji: '🐛' },
{ value: 'docs', name: '文档: 📝 文档变更', emoji: '📝' },
{ value: 'style', name: '格式: 🌈 代码格式调整', emoji: '🌈' },
{ value: 'refactor', name: '重构: 🔄 代码重构', emoji: '🔄' },
{ value: 'perf', name: '性能: 🚀 性能优化', emoji: '🚀' },
{ value: 'test', name: '测试: 🧪 测试相关修改', emoji: '🧪' },
{ value: 'build', name: '构建: 📦️ 构建流程变更', emoji: '📦️' },
{ value: 'ci', name: '集成: ⚙️ CI配置修改', emoji: '⚙️' },
{ value: 'revert', name: '回退: ↩️ 回滚提交', emoji: '↩️' },
{ value: 'chore', name: '其他: 🛠️ 辅助工具变更', emoji: '🛠️' }
],
useEmoji: true, // 启用 Emoji 显示
emojiAlign: 'center', // Emoji 居中对齐
useAI: false, // 关闭 AI 生成提交描述功能
aiNumber: 1,
themeColorCode: '',
// 项目模块范围(适配你的 pnpm workspace 结构)
scopes: [{ value: 'desktop', name: 'desktop: 桌面应用' }],
allowCustomScopes: true, // 允许手动输入自定义模块名称
allowEmptyScopes: false, // 不允许空模块(与 rules 中的 scope-empty 规则对应)
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false, // 不强制提交描述首字母大写
markBreakingChangeMode: false, // 不启用「重大变更」标记模式
allowBreakingChanges: ['feat', 'fix'], // 仅 feat/fix 类型可标注重大变更
breaklineNumber: 100, // 提交描述超过 100 字符自动换行
breaklineChar: '|', // 手动换行的分隔符
skipQuestions: [], // 不跳过任何交互式问题
// Issue 关联配置
issuePrefixes: [{ value: 'closed', name: 'closed: ISSUES has been processed' }],
customIssuePrefixAlign: 'top',
emptyIssuePrefixAlias: 'skip',
customIssuePrefixAlias: 'custom',
allowCustomIssuePrefix: true,
allowEmptyIssuePrefix: true,
confirmColorize: true, // 提交确认时高亮显示文本
maxHeaderLength: Infinity, // 不限制提交标题长度
maxSubjectLength: Infinity, // 不限制提交描述长度
minSubjectLength: 0, // 不限制提交描述最小长度
scopeOverrides: undefined,
defaultBody: '', // 默认提交详情为空
defaultIssues: '', // 默认不关联任何 Issue
defaultScope: '', // 默认不指定模块
defaultSubject: '' // 默认不填写提交描述
}
}

13
lint-staged.config.cjs Normal file
View File

@@ -0,0 +1,13 @@
module.exports = {
// 对所有JavaScript和TypeScript文件执行ESLint检查并自动修复
'*.{js,jsx,ts,tsx}': ['prettier --write'],
// 对样式文件执行Prettier格式化和StyleLint检查
'*.{css,scss,less}': ['stylelint --fix', 'prettier --write'],
// 对JSON、MD等文件执行Prettier格式化
'*.{json,md,yml,yaml}': ['prettier --write'],
// 对Vue文件同时进行ESLint和Prettier处理
'*.vue': ['prettier --write']
}

View File

@@ -18,7 +18,11 @@
"build:unpack": "npm run build && electron-builder --dir", "build:unpack": "npm run build && electron-builder --dir",
"build:win": "npm run build && electron-builder --win", "build:win": "npm run build && electron-builder --win",
"build:mac": "npm run build && electron-builder --mac", "build:mac": "npm run build && electron-builder --mac",
"build:linux": "npm run build && electron-builder --linux" "build:linux": "npm run build && electron-builder --linux",
"clean": "rimraf dist out",
"format:check": "prettier --check .",
"prepare": "husky",
"commit": "git add . && git-cz"
}, },
"dependencies": { "dependencies": {
"@arco-design/web-vue": "^2.57.0", "@arco-design/web-vue": "^2.57.0",
@@ -44,19 +48,25 @@
"zod": "^4.3.5" "zod": "^4.3.5"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^20.3.1",
"@commitlint/config-conventional": "^20.3.1",
"@electron-toolkit/eslint-config-prettier": "3.0.0", "@electron-toolkit/eslint-config-prettier": "3.0.0",
"@electron-toolkit/eslint-config-ts": "^3.1.0", "@electron-toolkit/eslint-config-ts": "^3.1.0",
"@electron-toolkit/tsconfig": "^2.0.0", "@electron-toolkit/tsconfig": "^2.0.0",
"@types/node": "^22.19.1", "@types/node": "^22.19.1",
"@vitejs/plugin-vue": "^6.0.2", "@vitejs/plugin-vue": "^6.0.2",
"commitizen": "^4.3.1",
"cz-git": "^1.12.0",
"electron": "^39.2.6", "electron": "^39.2.6",
"electron-builder": "^26.0.12", "electron-builder": "^26.0.12",
"electron-rebuild": "^3.2.9", "electron-rebuild": "^3.2.9",
"electron-vite": "^5.0.0", "electron-vite": "^5.0.0",
"eslint": "^9.39.1", "eslint": "^9.39.1",
"eslint-plugin-vue": "^10.6.2", "eslint-plugin-vue": "^10.6.2",
"husky": "^9.1.7",
"less": "^4.5.1", "less": "^4.5.1",
"prettier": "^3.7.4", "prettier": "^3.7.4",
"rimraf": "^6.1.2",
"typescript": "^5.9.3", "typescript": "^5.9.3",
"unocss": "^66.5.12", "unocss": "^66.5.12",
"unplugin-auto-import": "^20.3.0", "unplugin-auto-import": "^20.3.0",

953
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff