-
Notifications
You must be signed in to change notification settings - Fork 141
/
commitlint.config.js
58 lines (54 loc) · 1.77 KB
/
commitlint.config.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
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [2, 'always', ['chore', 'ci', 'docs', 'feat', 'fix', 'refactor', 'revert', 'style', 'test']],
'scope-empty': [2, 'never'],
'custom-scope-enum': [
2,
'always',
[
'global',
'ava',
'ava/advisor',
'ava/ckb',
'ava/data',
'ava/insight',
'ava/ntv',
'ava-react',
'ava-react/ntv',
'ava-react/insight-card',
],
],
},
plugins: [
{
rules: {
/**
* We need use '/' as the module separator
* However, commitlint use '/' for multiple scopes https://github.com/conventional-changelog/commitlint/blob/master/docs/concepts-commit-conventions.md#multiple-scopes
* So we add a plugin modified from https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/rules/src/scope-enum.ts
*/
'custom-scope-enum': (parsed, when = 'always', value = []) => {
if (!parsed.scope) {
return [true, ''];
}
// only use comma sign as separator
const delimiters = ',';
const scopeSegments = parsed.scope.split(delimiters);
const check = (value, enums) => {
if (value === undefined) {
return false;
}
if (!Array.isArray(enums)) {
return false;
}
return enums.indexOf(value) > -1;
};
const negated = when === 'never';
const result = value.length === 0 || scopeSegments.every((scope) => check(scope, value));
return [negated ? !result : result, `scope must ${negated ? 'not' : null} be one of [${value.join(', ')}]`];
},
},
},
],
};