-
Notifications
You must be signed in to change notification settings - Fork 1
/
commitlint.config.cjs
113 lines (104 loc) · 2.7 KB
/
commitlint.config.cjs
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
const { isRegExp } = require('lodash');
const scopes = [
'api',
'web',
'e2e',
'functions',
/functions\/(.*)/,
/packages\/(.*)/,
'tooling',
'api-testing'
];
// dependabot commit scopes
const dependabotScopes = [
'deps',
'deps-dev'
];
/** @type {import('@commitlint/types').UserConfig} */
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'body-max-line-length': [2, 'always', 120], // dependabot needs longer lines, the value is somewhat arbitrary
'scope-enums': [
2,
'always',
{
build: [null, ...dependabotScopes],
chore: [...scopes, ...dependabotScopes],
ci: [],
docs: [null, ...scopes],
feat: scopes,
fix: scopes,
perf: scopes,
refactor: scopes,
revert: [],
style: scopes,
test: [null, ...scopes]
}
]
},
plugins: [
{
rules: {
'scope-enums': (
{ type, scope },
condition,
/** @type {Record<string, (string | null)[]>} */ rule
) => {
if (!type) {
return [false, 'the scope could not be determined'];
}
if (condition === 'never') {
return [false, 'the "scope-enums" rule does not support "never"'];
}
const allowedScopes = rule[type];
// If the `type` does not appear in the rule config, allow any scope or no scope
if (!allowedScopes) {
return [true];
}
// If the `type` belongs to to an empty array in the rule config, any
// provided scope will be considered as not allowed
if (allowedScopes.length === 0) {
return scope === null
? [true]
: [false, `commit messages with type "${type}" must not specify a scope`];
}
// Otherwise attempt to match against either null, a string literal,
// or a regular expression
if (
allowedScopes.some((allowedScope) => {
if (isRegExp(allowedScope)) {
if (scope == null) {
return false;
}
return allowedScope.exec(scope) !== null;
} else {
return allowedScope === scope;
}
})
) {
return [true];
}
// If the allowed scopes contained null – i.e. a scope is optional,
// but the provided scope was not valid, fail on the basis that an
// allowed scope was not used
if (allowedScopes.includes(null)) {
return [
false,
`commit message with type "${type}" may specify a scope, but if specified, it must be one of the following: ${allowedScopes
.filter((s) => s !== null)
.map((s) => `"${s}"`)
.join(', ')}`
];
}
return [
false,
`commit message with type "${type}" must specify one of the following scopes: ${allowedScopes
.map((s) => `"${s}"`)
.join(', ')}`
];
}
}
}
]
};