-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommitlint.config.ts
59 lines (51 loc) · 1.62 KB
/
commitlint.config.ts
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
import { type UserConfig } from '@commitlint/types';
import { RuleConfigSeverity as Level } from '@commitlint/types';
import { readdirSync } from 'fs';
const packageDirectoryList: string[] = [];
try {
for (const item of readdirSync('./packages', { withFileTypes: true })) {
if (item.isDirectory()) {
packageDirectoryList.push(item.name);
}
}
} catch (error) {
// eslint-disable-next-line no-console
console.warn({ warning: error });
}
const scopeSeparator = /[,/]/gu;
const Configuration: UserConfig = {
extends: ['@commitlint/config-conventional'],
ignores: [(commit) => commit.startsWith('Pull request #')],
rules: {
'scope-empty': [Level.Error, 'never'],
'scope-enum': [Level.Error, 'always', ['root', ...packageDirectoryList]],
'scope-separates-with-comma-and-space': [Level.Error, 'always'],
},
plugins: [
{
rules: {
'scope-separates-with-comma-and-space': async ({ scope }) => {
if (scope) {
const separateCounter = [...scope.matchAll(scopeSeparator)];
if (separateCounter.length > 0) {
for (const [index, part] of scope
.split(scopeSeparator)
.entries()) {
const isValid =
index === 0 ? !part.startsWith(' ') : part.startsWith(' ');
if (isValid === false) {
return [
isValid,
`Use comma and space ", " before scope "${part}"`,
];
}
}
}
}
return [true];
},
},
},
],
};
export default Configuration;