-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommitlint.config.js
67 lines (61 loc) · 1.61 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
/**
* @example: :sparkles: #1 - feat: implement new feature
* @see {@link https://regexr.com/7qm0o RegExr}
* @type {RegExp}
*/
const COMMIT_PATTERN =
/(:\w+\:)(?:\s+(#\d+))?\s-\s([\w\s]+)(?:\((\w+)\))?:\s(.+)/;
// We can't use commitlint type enum here due to gitmoji.
const TYPE_ENUM = [
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"style",
"refactor",
"perf",
"test",
];
/**
* Simple commitlint plugin that allows a custom function to be executed.
* @type {{rules: {functionRule: (function(*, *, *): *)}}}
*/
const functionRulePlugin = {
rules: {
functionRule: (parsed, when, value) => {
if (typeof value !== "function") {
throw new Error(value, "is not a function!");
}
return value(parsed, when);
},
},
};
module.exports = {
plugins: [functionRulePlugin],
rules: {
"header-full-stop": [2, "never"],
functionRule: [
2,
"always",
({ header }) => {
const match = header.match(COMMIT_PATTERN);
if (match) {
const [header, gitmoji, ticket, type, scope, description] = match;
if (!TYPE_ENUM.includes(type)) {
// Message match but type is not in TYPE_ENUM.
return [false, `${type} is not in ${TYPE_ENUM.join(", ")}`];
}
// Message matched.
return [true, ""];
}
// Message did not match format.
return [
false,
"Commit message format invalid: \n\nFormat: <gitmoji>[ [ticket]] - <type>[([optional scope])]: <description>.\nExample: :sparkles: #1 - feat: implement new feature",
];
},
],
},
};