commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

commit lint issuePrefixes - scope could not be optional

Open Gaurang033 opened this issue 4 years ago • 6 comments

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

Gaurang033 avatar Mar 11 '20 02:03 Gaurang033

I am facing the same problem, thanks in advance for any advice on how to achieve this linting behaviour.

FabianEllenberger avatar May 12 '21 13:05 FabianEllenberger

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(.*)$/,

AdeAttwood avatar May 17 '21 07:05 AdeAttwood

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(.*)$/,

@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 avatar May 18 '21 08:05 FabianEllenberger

@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.

AdeAttwood avatar May 20 '21 19:05 AdeAttwood

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.

escapedcat avatar May 21 '21 01:05 escapedcat

remove scope empty or change scope empty's severity value to 0 'scope-empty': [0, 'always'], or remove it

MaheshCartrabbit avatar Nov 23 '22 10:11 MaheshCartrabbit