-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommitlint.config.js
More file actions
105 lines (94 loc) · 3.11 KB
/
commitlint.config.js
File metadata and controls
105 lines (94 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
module.exports = {
// 不继承默认配置,因为它会干扰我们的 gitemoji 格式
parserPreset: {
parserOpts: {
// 自定义解析器来处理 gitemoji 格式 - 支持 :emoji: 和 Unicode emoji
headerPattern:
/^((?::[a-z_]+:|\p{Emoji})\s*)\s+(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: (.{1,50})$/u,
headerCorrespondence: ['gitemoji', 'type', 'scope', 'subject'],
},
},
rules: {
// 基本规则
'header-max-length': [2, 'always', 72],
'body-leading-blank': [1, 'always'],
'body-max-line-length': [2, 'always', 100],
'footer-leading-blank': [1, 'always'],
'footer-max-line-length': [2, 'always', 100],
// 类型相关规则
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
'type-enum': [
2,
'always',
[
'feat',
'fix',
'docs',
'style',
'refactor',
'test',
'chore',
'perf',
'ci',
'build',
'revert',
],
],
// 主题相关规则
'subject-case': [
2,
'never',
['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
// 作用域规则
'scope-case': [2, 'always', 'lower-case'],
// 启用自定义 gitemoji 规则
'gitemoji-format': [2, 'always'],
},
plugins: [
{
rules: {
// 自定义规则:验证 gitemoji 格式 - 允许任何 gitemoji
'gitemoji-format': parsed => {
const { header } = parsed
// 更灵活的模式:支持 :emoji: 和 Unicode emoji
const gitemojiPattern =
/^(?::[a-z_]+:|\p{Emoji})\s*(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: .{1,50}$/u
if (!gitemojiPattern.test(header)) {
return [
false,
`Commit message must follow format: emoji type(scope): description
🎭 You can use either format:
• :emoji: (gitemoji format): :sparkles: feat(auth): add user authentication
• 🎉 (Unicode emoji): 🎉 feat(auth): add user authentication
🎭 Recommended gitemoji for each type:
:sparkles: ✨ - feat (new feature)
:bug: 🐛 - fix (bug fix)
:memo: 📝 - docs (documentation)
:lipstick: 💄 - style (formatting, styling)
:recycle: ♻️ - refactor (code refactoring)
:white_check_mark: ✅ - test (adding tests)
:wrench: 🔧 - chore (maintenance)
:zap: ⚡ - perf (performance improvements)
:green_heart: 💚 - ci (CI/CD changes)
:construction_worker: 👷 - build (build system)
:rewind: ⏪ - revert (revert changes)
💡 You can also use other emojis like:
:art: 🎨 :fire: 🔥 :rocket: 🚀 :tada: 🎉 :lock: 🔒
📝 Types: feat, fix, docs, style, refactor, test, chore, perf, ci, build, revert
✅ Examples:
:sparkles: feat(auth): add user authentication
🎉 feat(auth): add user authentication
:bug: fix(api): resolve login timeout issue
🐛 fix(api): resolve login timeout issue`,
]
}
return [true]
},
},
},
],
}