-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommitlint.config.cjs
More file actions
149 lines (136 loc) · 3.98 KB
/
Copy pathcommitlint.config.cjs
File metadata and controls
149 lines (136 loc) · 3.98 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const scopedTypes = new Set([
"build",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"test",
]);
const documentedScopes = new Set(["api", "auth"]);
function matchesScope(scope) {
return /^[a-z0-9][a-z0-9/-]*$/.test(scope);
}
module.exports = {
extends: ["@commitlint/config-conventional"],
defaultIgnores: true,
plugins: [
{
rules: {
"scope-required-for-type": (parsed) => {
const type = parsed.type ?? "";
const scope = parsed.scope ?? "";
if (!scopedTypes.has(type)) {
return [true];
}
return [
scope.length > 0,
`type "${type}" requires a scope, for example "${type}(api): ..."`,
];
},
"scope-format": (parsed) => {
const scope = parsed.scope ?? "";
if (scope.length === 0) {
return [true];
}
return [
matchesScope(scope),
"scope must be lowercase and may contain digits, hyphens, or slashes",
];
},
"subject-no-pr-suffix": (parsed) => {
const subject = parsed.subject ?? "";
return [
!/\s\(#\d+\)$/.test(subject),
"do not append PR numbers to the subject; use a footer like 'Refs: #123' instead",
];
},
"body-required-for-documented-change": (parsed) => {
const type = parsed.type ?? "";
const scope = parsed.scope ?? "";
const body = (parsed.body ?? "").trim();
if (
!(
documentedScopes.has(scope) &&
(type === "feat" || type === "fix")
)
) {
return [true];
}
return [
body.length > 0,
`commits like "${type}(${scope}): ..." must include a body describing the behavior or contract change`,
];
},
"body-required-for-breaking-change": (parsed) => {
const raw = parsed.raw ?? "";
const body = (parsed.body ?? "").trim();
const hasBreakingHeader = /^[a-z]+(?:\([^)]+\))?!:/.test(
parsed.header ?? "",
);
const hasBreakingFooter =
/(^|\n)BREAKING CHANGE: .+/m.test(raw) ||
/(^|\n)BREAKING-CHANGE: .+/m.test(raw);
if (!(hasBreakingHeader || hasBreakingFooter)) {
return [true];
}
return [
body.length > 0,
"breaking changes must include a body explaining the migration or behavior impact",
];
},
"breaking-change-footer-required": (parsed) => {
const raw = parsed.raw ?? "";
const hasBreakingHeader = /^[a-z]+(?:\([^)]+\))?!:/.test(
parsed.header ?? "",
);
const hasBreakingFooter =
/(^|\n)BREAKING CHANGE: .+/m.test(raw) ||
/(^|\n)BREAKING-CHANGE: .+/m.test(raw);
if (!hasBreakingHeader) {
return [true];
}
return [
hasBreakingFooter,
'commits using "!" in the header must include a "BREAKING CHANGE:" footer',
];
},
},
},
],
rules: {
"body-leading-blank": [1, "always"],
"body-required-for-breaking-change": [2, "always"],
"body-required-for-documented-change": [2, "always"],
"breaking-change-footer-required": [2, "always"],
"footer-leading-blank": [1, "always"],
"header-max-length": [2, "always", 100],
"scope-format": [2, "always"],
"scope-required-for-type": [2, "always"],
"subject-case": [
2,
"never",
["sentence-case", "start-case", "pascal-case", "upper-case"],
],
"subject-empty": [2, "never"],
"subject-full-stop": [2, "never", "."],
"subject-no-pr-suffix": [2, "always"],
"type-enum": [
2,
"always",
[
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"test",
],
],
},
};