// from https://github.com/arvinxx/gitmoji-commit-workflow/tree/master/packages/gitmoji-regex const isGitmoji = (commit) => commit.match( /^(?::\w*:|(?:\ud83c[\udf00-\udfff])|(?:\ud83d[\udc00-\ude4f\ude80-\udeff])|[\u2600-\u2B55]|♻️|🥅|🧱|🤡|🏷️|🚧|♻️|✏️|⚡️|🔥|⬆️|⏪|🦺|🗃️)\s(?\w*)(?:\((?.*)\))?!?:\s(?(?:(?!#).)*(?:(?!\s).))(?:\s\(?(?#\d*)\)?)?$/gm, ); const isConventional = (commit) => commit.match( /^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert|merge)(\(.+\))?:\s/, ); module.exports = { extends: ['@commitlint/config-conventional', 'gitmoji'], rules: { 'subject-empty': () => { const commitMsg = process.env.COMMIT_MSG || ''; return isGitmoji(commitMsg) ? [0, 'always'] : [2, 'never']; }, 'type-empty': () => { const commitMsg = process.env.COMMIT_MSG || ''; return isGitmoji(commitMsg) ? [0, 'always'] : [2, 'never']; }, 'start-with-gitmoji': () => { const commitMsg = process.env.COMMIT_MSG || ''; return isGitmoji(commitMsg) && !isConventional(commitMsg) ? [2, 'never'] : [0, 'always']; }, }, };