-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcommitlint.config.js
82 lines (77 loc) · 2.29 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const fs = require('fs');
const commitEditMsg = '.git/COMMIT_EDITMSG';
const types = [
'feat',
'fix',
'build',
'ci',
'docs',
'perf',
'refactor',
'style',
'test',
'hotfix',
'release',
'chore',
'revert'
];
const typeDesc = {
feat: ' new features, new functions',
fix: ' fix normal no-emergency bug',
build: ' changes that affect the build system, version release or external dependencies',
ci: ' changes to CI configuration or scripts',
docs: ' changes to the document',
perf: ' optimize related, such as improving performance and experience',
refactor: 'code refactoring',
style: ' changes to the code format',
test: ' add new function tests or changes to the origin test module',
hotfix: ' urgent need to fix the online bug',
release: ' version release',
chore: ' changes in the build process or the auxiliary tools',
revert: ' revert to the previous version'
};
const exampleList = [
'feat: add new features',
'feat(features): add new features'
];
function parseMessage(message) {
const PATTERN = /(\w*)(?:\((.*)\))?: (.*)$/;
const header = message.split('\n')[0];
const match = PATTERN.exec(header);
if (match) {
return {
type: match[1] || null,
scope: match[2] || null,
subject: match[3] || null
};
}
return null;
}
function getTypeEnumRule() {
const messages = fs.readFileSync(commitEditMsg, { encoding: 'utf-8' });
const myMessage = parseMessage(messages);
if (myMessage) {
const { type } = myMessage;
if (type === 'hotfix' || type === 'release' || type === 'chore' || type === 'revert') {
return [2, 'always', types];
}
}
console.log('Please strictly follow the following rules, such as:');
console.log(types.map(e => `${e}(optional): message ${typeDesc[e]}`));
console.log('Examples:');
exampleList.forEach(e => console.log(e));
return [2, 'always', types.map(e => `${e}`)];
}
module.exports = {
extends: ['@commitlint/config-angular'],
rules: {
'body-leading-blank': [1, 'always'],
'footer-leading-blank': [1, 'always'],
'header-max-length': [2, 'always', 300],
'scope-case': [2, 'always', 'lower-case'],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'type-empty': [2, 'never'],
'type-enum': getTypeEnumRule
}
};