-
Notifications
You must be signed in to change notification settings - Fork 2
/
commitlint.config.js
31 lines (26 loc) · 1.06 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
const pkg = require('./package.json');
// Check if the user has configured the package to use conventional commits.
const isConventional = pkg.config ? pkg.config['cz-emoji']?.conventional : false;
// Regex for default and conventional commits.
const RE_DEFAULT_COMMIT =
/^(?::.*:|(?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))\s(?<emoji>\((?<scope>.*)\)\s)?.*$/gm;
const RE_CONVENTIONAL_COMMIT =
/^^(?<type>\w+)(?:\((?<scope>\w+)\))?\s(?<emoji>:.*:|(?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))\s.*$/gm;
module.exports = {
rules: {
'cz-emoji': [2, 'always'],
},
plugins: [
{
rules: {
'cz-emoji': ({ raw }) => {
const isValid = isConventional ? RE_CONVENTIONAL_COMMIT.test(raw) : RE_DEFAULT_COMMIT.test(raw);
const message = isConventional
? `Your commit message should follow conventional commit format.`
: `Your commit message should be: <emoji> (<scope>)?: <subject>`;
return [isValid, message];
},
},
},
],
};