question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

commit lint issuePrefixes - scope could not be optional

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
FabianEllenbergercommented, May 18, 2021

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?

1reaction
AdeAttwoodcommented, May 17, 2021

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(.*)$/,
Read more comments on GitHub >

github_iconTop Results From Across the Web

commitlint not able to make scope optional - Stack Overflow
The rule 'scope-empty': [1, 'never'], is means display warning if scope is not empty. If you want to disable this rule completely, ...
Read more >
standard-commit - npm
Start using standard-commit in your project by running `npm i ... There are no other projects in the npm registry using standard-commit.
Read more >
commitlint - Lint commit messages
commitlint helps your team adhere to a commit convention. By supporting npm-installed configurations it makes sharing of commit conventions easy.
Read more >
commitlint - Bountysource
I'd like it to be purely optional and not block the commit in case it finds problems with ... Error: Cannot find module...
Read more >
Git Commit Guidelines | EU System
Commit Message Format ... The header is mandatory and the scope of the header is optional. Any line of the commit message cannot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found