import pkg from './package.json' // Check if the user has configured the package to use conventional commits. // @ts-expect-error package.json is not typed. 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(?\((?.*)\)\s)?.*$/gm const RE_CONVENTIONAL_COMMIT = /^^(?\w+)(?:\((?\w+)\))?\s(?:.*:|(?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))\s.*$/gm export default { rules: { 'cz-emoji': [2, 'always'], }, plugins: [ { rules: { 'cz-emoji': ({ raw }: { raw: string }) => { 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: ()?: ` return [isValid, message] }, }, }, ], }