-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (83 loc) · 2 KB
/
index.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
module.exports = {
plugins: ["commitlint-plugin-function-rules"],
parserPreset: {
parserOpts: { headerPattern: /^(\w*)(?:\((.*)\))?!?: (.*)$/ }
},
rules: {
"body-leading-blank": [2, "always"],
"footer-leading-blank": [2, "always"],
"header-max-length": [2, "always", 72],
"subject-case": [
2,
"never",
["sentence-case", "start-case", "pascal-case", "upper-case"]
],
"subject-full-stop": [2, "never", "."],
"type-case": [2, "always", "lower-case"],
"type-enum": [
2,
"always",
[
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"style",
"test"
]
],
"function-rules/scope-enum": [
2,
"always",
parsed => {
if (parsed.scope && parsed.scope.toUpperCase() !== parsed.scope) {
if (!parsed.raw?.startsWith("revert")) {
return [false, "scope must be upper-case"];
} else {
if (
parsed.raw?.match(
/^(?:revert\(([A-Z]+-[0-9]+)\)!?: )(\w*)(?:\(([A-Z]+-[0-9]+)\))!?: (.*)$/
)
) {
return [true];
} else {
return [false, "scope must be upper-case"];
}
}
}
if (parsed.scope?.match(/[A-Z]+-[0-9]+/)) {
if (parsed.type === "revert") {
return [
false,
"revert commits should have the full commit name that is being reverted"
];
} else {
return [true];
}
}
if (parsed.raw?.match(/^(\w*)(?:\(([A-Z]+-[0-9]+)\))!?: (.*)$/)) {
return [true];
}
if (parsed.raw?.match(/^(\w*)(?:\(([A-Z]+-[0-9]+)\))?!?: (.*)$/)) {
if (parsed.type === "revert") {
return [
false,
"revert commits should have the associated JIRA ID includes in the revert scope"
];
} else {
return [false, `a scope must be set`];
}
}
if (!parsed.subject) {
return [false, `a subject must be set`];
}
return [false, `scope must be a JIRA issue ID`];
}
]
}
};