chore(repo): improve commit lint script to allow breaking change syntax (#12293)

This commit is contained in:
Miroslav Jonaš 2022-09-28 20:39:09 +02:00 committed by GitHub
parent f30ed24aaf
commit 8d588c96c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,12 +8,10 @@ const gitMessage = require('child_process')
.toString() .toString()
.trim(); .trim();
const allowedTypes = types.map((type) => type.value); const allowedTypes = types.map((type) => type.value).join('|');
const allowedScopes = scopes.map((scope) => scope.name); const allowedScopes = scopes.map((scope) => scope.name).join('|');
const commitMsgRegex = `(${allowedTypes.join('|')})\\((${allowedScopes.join( const commitMsgRegex = `(${allowedTypes})\\((${allowedScopes})\\)!?:\\s(([a-z0-9:\-\s])+)`;
'|'
)})\\):\\s(([a-z0-9:\-\s])+)`;
const matchCommit = new RegExp(commitMsgRegex, 'g').test(gitMessage); const matchCommit = new RegExp(commitMsgRegex, 'g').test(gitMessage);
const matchRevert = /Revert/gi.test(gitMessage); const matchRevert = /Revert/gi.test(gitMessage);
@ -32,13 +30,12 @@ if (exitCode === 0) {
); );
console.log('\ntype(scope): subject \n BLANK LINE \n body'); console.log('\ntype(scope): subject \n BLANK LINE \n body');
console.log('\n'); console.log('\n');
console.log(`possible types: ${allowedTypes.join('|')}`); console.log(`possible types: ${allowedTypes}`);
console.log( console.log(`possible scopes: ${allowedScopes} (if unsure use "core")`);
`possible scopes: ${allowedScopes.join('|')} (if unsure use "core")`
);
console.log( console.log(
'\nEXAMPLE: \n' + '\nEXAMPLE: \n' +
'feat(nx): add an option to generate lazy-loadable modules\n' 'feat(nx): add an option to generate lazy-loadable modules\n' +
'fix(core)!: breaking change should have exclamation mark\n'
); );
} }
process.exit(exitCode); process.exit(exitCode);