I am using commit lint and I want to use conventional commits but i want to include a Jira Ticket.
Example TEST-23: fix: my body
In my case I needed to create a custom parser and a plugin with a custom rule.
const jiraTicketRegex = /^[A-Z]+-\d+$/;
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'subject-case': [2, 'always', 'sentence-case'],
'header-max-length': [2, 'always', 100],
'jira-ticket-format': [2, 'always'],
},
parserPreset: {
parserOpts: {
headerPattern: /^([A-Z]+-\d+)\s*:\s*(\w*): (.*)$/,
headerCorrespondence: ['ticket', 'type', 'subject'],
},
},
plugins: [
{
rules: {
'jira-ticket-format': (parsed) => {
const ticket = parsed.ticket;
if (!jiraTicketRegex.test(ticket)) {
return [
false,
`Wrong format".`,
];
}
return [true];
},
},
},
],
};