Closed evanjmg closed 3 years ago
Great question! There is a digitalroute-commitlint-config that you can download and use. It is basically the standard config with just minor modifications. We add a custom rule (has-jira-issue
) for checking if the commit has a jira issue in the expected location. We also ban scope, and add our own types.
This is the whole config that you can copy and make your own:
const types = require('@digitalroute/cz-conventional-changelog-for-jira/types')
.types;
module.exports = {
extends: ['@commitlint/config-conventional'],
plugins: [
{
rules: {
'has-jira-issue': function(parsed, when = 'always', value = 'DAZ') {
const { subject } = parsed;
const negated = when === 'never';
const issueRegex = `${value}-\\d+\\s.*`;
const matches = new RegExp(issueRegex, 'u').test(subject);
const pass = negated !== matches;
const errorMessage = [
'subject',
negated ? 'may not' : 'must',
`include a JIRA-issue matching: ${value}-[0-9]+`,
].join(' ');
return [pass, errorMessage];
},
},
},
],
rules: {
'scope-empty': [2, 'always'],
'type-enum': [2, 'always', Object.keys(types)],
'subject-case': [0, 'always'],
'has-jira-issue': [2, 'always'],
},
};
I think a great idea would be to link to this config or add it to the docs.
@polarn
This is closed for me, but feel free to add it to the docs
@juliuscc Your package and config example above is now broken because of:
const types = require('@digitalroute/cz-conventional-changelog-for-jira/types')
.types; <-- this
since 08224222f6c451a5620c54791bc872d74d84753d
Ah that sucks. Can you update the docs with a PR @KnifeFed ?
@juliuscc Update which docs with what? 🙂 Wouldn't it be better to just remove .types
in the package so it works again?
Can confirm - I'm experiencing the same error.
Is there any guidance on commitlint with this library? The subject-case rule fails when we put the jira ticket in the subject. Right now I just disable that rule and it works but it be good to get some advice what you all did?