forked from horuslabsio/seamlessui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commitlint.config.js
83 lines (75 loc) · 2.42 KB
/
commitlint.config.js
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
const capturingGroupType = /(\w*:\s)/; // 'type: '
const capturingGroupSubject = /([^[].+)/; // 'subject'
/*
❌ Bad commit messages
git commit -m "fix something"
// No type specified; needs to be in 'type: subject' format.
git commit -m "TASK-456 fix something"
// Includes an identifier but lacks the 'type:' prefix.
git commit -m "fix - something"
// Uses incorrect separator; should be 'fix: something'.
✅ Good commit messages
git commit -m "fix: correct issue in user login"
// Correct format with 'type: subject'. 'fix' is a valid type and 'correct issue in user login' is the subject.
git commit -m "[TASK-456] fix: correct issue in user login"
// Includes an identifier (optional) and correctly follows 'type: subject' format.
*/
module.exports = {
parserPreset: {
parserOpts: {
headerPattern: new RegExp(
"^" + capturingGroupType.source + capturingGroupSubject.source + "$"
),
headerCorrespondence: ["type", "subject"],
},
},
plugins: [
{
rules: {
"header-match-pattern": (parsed) => {
const { type, subject } = parsed;
if (type === null && subject === null) {
return [false, "commit message must be in format 'type: subject'"];
}
return [true, ""];
},
"check-type": (parsed, _when, expectedValue) => {
const { type } = parsed;
if (
type &&
!Object.keys(expectedValue).includes(type.split(":")[0])
) {
return [
false,
`commit message must be in format 'type: subject'\ntype must be one of:\n${Object.keys(
expectedValue
)
//type - description
.map((type) => `${type} - ${expectedValue[type]}`)
.join("\n")}`,
];
}
return [true, ""];
},
},
},
],
rules: {
"header-match-pattern": [2, "always"],
"check-type": [
2,
"always",
{
feat: "A new feature ",
chore: "Tooling, configuration changes, or maintenance updates",
fix: "A bug fix",
docs: "Documentation updates",
refactor: "Code changes that do not add new features",
perf: "improving performance",
test: "Adding or updating tests",
style: "CSS or styling changes",
build: "changes that affect the build system",
},
],
},
};