-
Notifications
You must be signed in to change notification settings - Fork 1
/
commitlint.config.cjs
123 lines (109 loc) · 3.01 KB
/
commitlint.config.cjs
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const commitTypeRegex = /chore|ci|docs|feat|fix|perf|refactor|release|style|test/;
const commitEmojiRegex =
/(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/;
const commitTicketIdRegex = /(\[((((?<!([A-Z]{1,10})-?)[A-Z]+-\d+)))\])/;
const emptyCommitTicketIdRegex = /(\[((((?<!([A-Z]{1,10})-?)[A-Z]+-0+)))\])/;
const commitMessageRegex = /([^\s]+\s)*[^\s]+/;
const commitRegex = new RegExp(
`^(${commitTypeRegex.source}): (${commitEmojiRegex.source} )?(${commitTicketIdRegex.source} )?(${commitMessageRegex.source})$`,
);
const defaultCommitTypes = [
{
description: 'Build process or auxiliary tool changes',
emoji: '🤖',
value: 'chore',
},
{
description: 'CI related changes',
emoji: '🚀',
value: 'ci',
},
{
description: 'Documentation only changes',
emoji: '📘',
value: 'docs',
},
{
description: 'A new feature',
emoji: '🔥',
value: 'feat',
},
{
description: 'A bug fix',
emoji: '🐞',
value: 'fix',
},
{
description: 'A code change that improves performance',
emoji: '⚡',
value: 'perf',
},
{
description: 'A code change that neither fixes a bug or adds a feature',
emoji: '💡',
value: 'refactor',
},
{
description: 'Create a release commit',
emoji: '🔖',
value: 'release',
},
{
description: 'Markup, white-space, formatting, missing semi-colons...',
emoji: '🎨',
value: 'style',
},
{
description: 'Adding missing tests',
emoji: '✅',
value: 'test',
},
];
module.exports = {
plugins: [
{
rules: {
'header-match-team-pattern': (parsed) => {
const { header } = parsed;
if (!commitRegex.test(header)) {
return [
false,
"header must be in format '<type>: <emoji?> <ticket?> <subject>\nexample => ci: 🚀 [V-123] example\n",
];
}
if (emptyCommitTicketIdRegex.test(header)) {
return [false, 'ticket ID must not be empty (or 00..0)\n'];
}
return [true, ''];
},
'explained-emoji-enum': (parsed, _when, commitTypes) => {
const { header } = parsed;
const emojiInHeader = header.match(commitEmojiRegex);
if (!emojiInHeader) {
return [true, ''];
}
const isEmojiInArray =
commitTypes.findIndex((commitType) => commitType.emoji === emojiInHeader[0]) !== -1;
if (!isEmojiInArray) {
const messageArray = commitTypes.map(
(commitType) => `${commitType.emoji} - ${commitType.description}`,
);
return [false, `emoji must be one of:\n${messageArray.join('\n')}`];
}
return [true, ''];
},
},
},
],
rules: {
'header-match-team-pattern': [2, 'always'],
'explained-emoji-enum': [2, 'always', defaultCommitTypes],
'body-leading-blank': [2, 'always'],
'body-max-line-length': [2, 'always', 100],
'footer-leading-blank': [2, 'always'],
'footer-max-line-length': [2, 'always', 100],
'header-max-length': [2, 'always', 100],
'subject-case': [2, 'never', ['sentence-case', 'start-case', 'pascal-case', 'upper-case']],
'scope-empty': [2, 'always'],
},
};