-
Notifications
You must be signed in to change notification settings - Fork 3
/
commitlint.config.ts
50 lines (45 loc) · 1.44 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
import { type UserConfig } from '@commitlint/types';
import { ProjectPrefix } from './project.config';
const COMMIT_MODIFIERS = ['+', '*', '-'];
const COMMIT_MESSAGE_REGEXP = new RegExp(
`^(((${ProjectPrefix.APP})-[0-9]{1,6})|(${ProjectPrefix.ENVIRONMENTS.join(
'|',
)})): ([${COMMIT_MODIFIERS.join(',')}]) (.*\\S)$`,
);
const COMMIT_MESSAGE_MATCH_RULE_MESSAGE = `commit message doesn't match format requirements
Commit message must have one of the following formats:
- <project-prefix>-<issue-number>: <modifier> <description>
- <environment>: <modifier> <description>
Where:
- <project-prefix>: ${ProjectPrefix.APP}
- <modifier>: ${COMMIT_MODIFIERS.join(', ')}
- <environment>: ${ProjectPrefix.ENVIRONMENTS.join(', ')}
Examples:
- wr-5: + articles feed page
- wr-12: * create article form
- production: - comments in ui/ux homework`;
const configuration: UserConfig = {
parserPreset: {
parserOpts: {
headerPattern: COMMIT_MESSAGE_REGEXP,
headerCorrespondence: ['prefix', 'modifier', 'description'],
},
},
defaultIgnores: true,
plugins: [
{
rules: {
'commit-message-match': ({ header }): [true] | [false, string] => {
if (!COMMIT_MESSAGE_REGEXP.test(header)) {
return [false, COMMIT_MESSAGE_MATCH_RULE_MESSAGE];
}
return [true];
},
},
},
],
rules: {
'commit-message-match': [2, 'always'],
},
};
export default configuration;