-
Notifications
You must be signed in to change notification settings - Fork 1
/
commitlint.config.cjs
118 lines (105 loc) Β· 2.81 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
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 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",
];
}
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'],
},
};