Repository navigation
Expand file tree
/
Copy pathcommitlint.config.cjs
More file actions
57 lines (55 loc) · 1.69 KB
/
Copy pathcommitlint.config.cjs
File metadata and controls
57 lines (55 loc) · 1.69 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
const allowedTypes = [
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"simplify",
"style",
"test",
];
// GitHub appends " (#<number>)" to a squash-merged pull request's title. The
// reference is a link GitHub adds after review, so the length limit measures
// only the header the author wrote.
const pullRequestReference = / \(#\d+\)$/;
module.exports = {
defaultIgnores: false,
plugins: [
{
rules: {
"authored-header-max-length": (parsed, _when, maxLength) => {
const authored = (parsed.header ?? "").replace(pullRequestReference, "");
return [
authored.length <= maxLength,
`header must not be longer than ${maxLength} characters excluding a trailing pull request reference, current length is ${authored.length}`,
];
},
},
},
],
ignores: [
(message) => /^Merge[ \t]/.test(message),
// Git-generated revert headers quote the reverted subject verbatim, so the
// header cannot satisfy the typed-header rules. Accept the canonical
// header whether the body is Git's autogenerated "This reverts commit"
// line or an author-written explanation of why the revert was needed.
(message) => /^Revert "[^\r\n]+"(?:\r?\n(?:\r?\n[\s\S]*)?)?$/.test(message),
],
parserPreset: {
name: "tracedecay",
parserOpts: {
headerCorrespondence: ["type", "scope", "breaking", "subject"],
headerPattern: /^(\w*)(?:\(([A-Za-z0-9._/-]+)\))?(!)?: ([^\s].*)$/,
},
},
rules: {
"authored-header-max-length": [2, "always", 72],
"subject-empty": [2, "never"],
"type-empty": [2, "never"],
"type-enum": [2, "always", allowedTypes],
},
};