commitlint
commitlint copied to clipboard
commit lint issuePrefixes - scope could not be optional
I am trying to use issue prefix to have my commit format as mentioned below
JIRA-ID: type(scope): Subject
scope should be optional.
which means following are valid message
-
AAAA-12: fix(test): fixed the failing test
-
AAAA-12: fix: fixed the failing test
Following is how my commitlint.config.js looks like
module.exports = {
extends: ['@commitlint/config-conventional'],
parserPreset: {
parserOpts: {
headerPattern: /^[A-Z]{1,4}-[0-9]{1,4}:\s(\w*)\((\w*)\):\s(.*)$/,
headerCorrespondence: ["type", "scope", "subject"],
issuePrefixes: ["^[A-Z]{1,4}-[0-9]{1,4}"],
referenceActions: ["xxx-"] // (!!)
}
},
rules: {
'references-empty': [2, 'never'],
'scope-empty': [1, 'never'],
...
...
}
}
Expected Behavior
following message should be valid.
-
AAAA-12: fix(test): fixed the failing test
-
AAAA-12: fix: fixed the failing test
Need to understand how to extend the current config to add one more rule for prefix.
Current Behavior
following message appears to be invalid. I can't make scope optional
- AAAA-12: fix: fixed the failing test
Affected packages
- [ ] cli
- [ ] core
- [ ] prompt
- [ ] config-angular
Possible Solution
Steps to Reproduce (for bugs)
Change the parserPreset as mentioned above with rules mentioned.
commitlint.config.js
```js ```Context
Your Environment
Executable | Version |
---|---|
commitlint --version |
VERSION |
git --version |
VERSION |
node --version |
VERSION |
I am facing the same problem, thanks in advance for any advice on how to achieve this linting behaviour.
I think this is missing a ?
in the headerPattern
. Can you please try the below pattern and let me know how it goes
headerPattern: /^[A-Z]{1,4}-[0-9]{1,4}:\s(\w*)(?:\((.*)\))?: (.*)$/,
+headerPattern: /^[A-Z]{1,4}-[0-9]{1,4}:\s(\w*)(?:\((.*)\))?: (.*)$/,
-headerPattern: /^[A-Z]{1,4}-[0-9]{1,4}:\s(\w*)\((\w*)\):\s(.*)$/,
I think this is missing a
?
in theheaderPattern
. Can you please try the below pattern and let me know how it goesheaderPattern: /^[A-Z]{1,4}-[0-9]{1,4}:\s(\w*)(?:\((.*)\))?: (.*)$/,
+headerPattern: /^[A-Z]{1,4}-[0-9]{1,4}:\s(\w*)(?:\((.*)\))?: (.*)$/, -headerPattern: /^[A-Z]{1,4}-[0-9]{1,4}:\s(\w*)\((\w*)\):\s(.*)$/,
@AdeAttwood Thanks for your suggestion! This pattern has worked for me with the following options:
parserOpts: {
headerPattern: /^[A-Z]{1,4}-[0-9]{1,4}:\s(\w*)(?:\((.*)\))?: (.*)$/,
headerCorrespondence: ['type', 'scope', 'subject'],
issuePrefixes: ['^XXXX-[0-9]{1,4}']
}
Using the following commit message:
-
XXXX-0000: feat: subject
-
XXXX-0000: feat(scope): subject
Also the following commit messages will fail as expected with reasonable error logs:
-
XX-0000: test: subject
-
XXXX-AA: feat: subject
I didn't need to use referenceActions
, i think it's not necessary since issuePrefixes
with the above settings already works like expected. Or do you @AdeAttwood know what referenceActions
would achieve in this setting?
@FabianEllenberger if its working with your config then I would roll with that. TBH from reading the README.md of the paser it not that clear to me what to referenceActions dose.
Looking at this issue referenceActions
is related to the verb for that action at the end of a commit? Not sure. I just see this sometimes in projects.
remove scope empty or change scope empty's severity value to 0
'scope-empty': [0, 'always'],
or remove it