-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathcommitlint.config.mjs
More file actions
96 lines (91 loc) · 1.94 KB
/
commitlint.config.mjs
File metadata and controls
96 lines (91 loc) · 1.94 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
const PUBLIC_PACKAGES = [
"builder",
"cli",
"documentation",
"fs",
"logger",
"project",
"server",
];
const INTERNAL_PACKAGES = [
"documentation",
"shrinkwrap-extractor"
];
const ALLOWED_TYPE_SCOPE_COMBINATIONS = {
"build": ["deps-dev"],
"ci": ["github-actions", "release-please"],
"deps": [...PUBLIC_PACKAGES, ...INTERNAL_PACKAGES],
"feat": PUBLIC_PACKAGES,
"fix": PUBLIC_PACKAGES,
};
const ALL_SCOPES = Object.values(ALLOWED_TYPE_SCOPE_COMBINATIONS).flat();
export default {
extends: [
"@commitlint/config-conventional",
],
rules: {
"type-enum": [
2,
"always",
[
"build",
"ci",
"deps",
"docs",
"feat",
"fix",
"perf",
"refactor",
"release",
"revert",
"style",
"test",
],
],
"body-max-line-length": [2, "always", 160],
"footer-max-line-length": [0],
"subject-case": [
2, "always",
["sentence-case", "start-case", "pascal-case"],
],
// Limit scope to package names and special cases
"scope-enum": [
2,
"always",
ALL_SCOPES,
],
"scope-case": [2, "always", "lowercase"],
// Enable custom rule for type-scope combinations (see code below)
"custom/type-scope-combination": [
2,
"always",
],
},
ignores: [
// Ignore release commits, as their subject doesn't start with an uppercase letter
(message) => message.startsWith("release: v"),
],
plugins: [
{
rules: {
"custom/type-scope-combination": ({type, scope}) => {
// If no scope, it's valid
if (!scope) {
return [true];
}
// If type not in restrictions, allow any scope
if (!ALLOWED_TYPE_SCOPE_COMBINATIONS[type]) {
return [true];
}
// Check if the combination is allowed
const isAllowed = ALLOWED_TYPE_SCOPE_COMBINATIONS[type].includes(scope);
return [
isAllowed,
`Scope "${scope}" is not allowed with type "${type}". ` +
`Allowed scopes: ${ALLOWED_TYPE_SCOPE_COMBINATIONS[type].join(", ")}`
];
}
}
}
]
};