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.

cz commitlint CLI question customization for custom rules.

See original GitHub issue

I would like to add the ability to add a CLI prompt for a custom rule. (e.g. ticket number included in commit message)

Expected Behavior

Would like for a way to add new custom option to add ticket number to the CLI prompt. feat(button): added theme settings [TICKET-123] commitlint.config.js

module.exports = {
    extends: ['@commitlint/config-conventional'],
    plugins: [
        {
          rules: {
            ticket: ({ subject }) => {
              const ticketRegex = /(\w+-{1}\d+)/;
              return [
                ticketRegex.test(subject),
                "Your subject should include the ticket, for example PRJ-300.",
              ];
            },
          },
        },
      ],
    rules: {
      ticket: [2, "always"],
    },
    parserPreset: './parser-presets.js',
    prompt: {
        questions: {
          // ...
          subject: {
            description: 'Write a short, imperative tense description of the change',
          },
          ticket: {
            description: 'Provide a Ticket Number',
          },
          body: {
            description: 'Provide a longer description of the change',
          },
          // ...
        },
      }
}


parser-preset.js

module.exports = {
    parserOpts: {
      headerPattern: /^(\w+)\(\w+\):[ ]{1}(\w{1}.+\w{1})[ ]{1}\[(\w+-{1}\d+)\]$/,
      headerCorrespondence: ['type', 'scope', 'subject', 'ticket'],
    },
  };

Current Behavior

Currently ignores my new rule / custom CLI prompt. I can’t find any documentation that directly walks through this process of making a custom prompt with a custom rule. You can override current rules and change language. But unable to have question use new custom made rules. If this isn’t something that can be / is supported that’s perfectly fine! I’m just curious if it’s currently possible, and if it is where I may be tripping up.

Affected packages

  • cli
  • cz-commitlint
Executable Version
commitlint --version 12.1.4
git --version 2.32.0
node --version 14.17.1

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

5reactions
chrwlkcommented, Oct 13, 2021

I had the same issue. With the help of this comment I was able to fix it by adding a rule for each header correspondence. Otherwise it was just being ignored.

So I ended up with something similar to this:

rules: {
  "type-empty": [2, "never"],
  "scope-empty": [2, "never"],
  "subject-empty": [2, "never"],
  "ticket": [2, "always"],
}

Hope it helps!

1reaction
tomaviccommented, Jun 18, 2022

@escapedcat 😂 I forgot to paste it . Here it is

I find it too much configurations which didn’t work for me

The second one here seems a bit interesting as it uses emojis too with no problems.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make everyone in your project write beautiful commit ...
Now create a file in your root folder named .cz-config.js to customize the options of the CLI helper, and paste the below config....
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 >
Setup and Customize Conventional Commits and Semantic ...
Allows one to customize the changelog generation and other bits in the process. Conventional Commits Standards (specification) is a useful ...
Read more >
cz-customizable | Yarn - Package Manager
Commitizen customizable adapter following the conventional-changelog format. readme. cz-customizable. The customizable Commitizen plugin (or standalone utility) ...
Read more >
Additional command on Husky Hooks fail - Stack Overflow
Have you tried with this: "husky": { "hooks": { "prepare-commit-msg": "exec < /dev/tty && git cz --hook || true" } }.
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