-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommitlint.config.js
More file actions
76 lines (71 loc) · 2.77 KB
/
commitlint.config.js
File metadata and controls
76 lines (71 loc) · 2.77 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
const WIP_REGEX = /^wip[:]?$/i;
const RULE_ERROR_LEVEL = 2;
const HEADER_MAX_LENGTH = 150;
const SUBJECT_MIN_LENGTH = 5;
module.exports = {
extends: ["@commitlint/config-conventional"],
rules: {
"custom-subject-empty": [RULE_ERROR_LEVEL, "never"],
"custom-type-enum": [RULE_ERROR_LEVEL, "always"],
"custom-no-wip": [RULE_ERROR_LEVEL, "always"],
"custom-no-wip-subject": [RULE_ERROR_LEVEL, "always"],
"subject-min-length": [RULE_ERROR_LEVEL, "always", SUBJECT_MIN_LENGTH],
"subject-case": [0], // optional: allow flexibility in subject case
"header-max-length": [RULE_ERROR_LEVEL, "always", HEADER_MAX_LENGTH]
},
plugins: [
{
rules: {
"custom-subject-empty": ({ subject }) =>
subject && subject.trim().length > 0
? [true]
: [
false,
"The commit needs a description after the colon (:). Eg: feat: add new feature"
],
"custom-type-enum": ({ type }) => {
const allowedTypes = [
"feat",
"fix",
"hotfix",
"docs",
"style",
"refactor",
"test",
"chore"
];
if (!type) {
return [
false,
"Missing type. Use: feat, fix, chore, refactor, etc."
];
}
if (!allowedTypes.includes(type)) {
return [
false,
`Type "${type} is invalid". Allowed types: ${allowedTypes.join(
", "
)}`
];
}
return [true];
},
"custom-no-wip": ({ header }) => {
const isWipOnly = WIP_REGEX.test(header.trim());
return [
!isWipOnly,
"Commit message cannot be just \"WIP\" (use a descriptive message)."
];
},
"custom-no-wip-subject": ({ subject }) => {
if (!subject) return [true];
const isWipOnly = WIP_REGEX.test(subject.trim());
return [
!isWipOnly,
"Subject cannot be just \"WIP\". Use a descriptive message like \"implement user login\" instead."
];
}
}
}
]
};