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.

How to use parser headerPattern

See original GitHub issue

The task is to use commitlint to prevent commits from being commited. I use husky as well when I test it and run echo "bla bla bla" | npx commitlint It doesn’t catch anything and shows no errors found

⧗   input: bla bla bla 
✔   found 0 problems, 0 warnings 

Please, help, why it ignores parserOpts.headerPattern ? Also some other notice: I need at least one rule, otherwise commitlint doesn’t want to run Do I need to add headerCorrespondence to make it work or I can have headerPattern only? Can I customize report message in case if I headerPattern is not matched?

commitlint.config.js

module.exports = {
  rules: {
    'header-min-length': [2, 'always', 20],
  },
  parserPreset: {
    parserOpts: {
      headerPattern: /^(feat|fix|perf|test|BREAKING CHANGE):.*\[REF-(\d{3,}|N\\A)\] \S+ \S+ \S+ \S+ \S+/,
      headerCorrespondence: ['type', 'scope', 'subject']
    }
  }
};

husky in package.json

  "husky": {
    "hooks": {
      "pre-push": "npm test",
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  }

I installed the next

    "@commitlint/cli": "^7.5.2",
    "@commitlint/parse": "^7.5.0",

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:18 (1 by maintainers)

github_iconTop GitHub Comments

18reactions
mistrickycommented, May 27, 2021

There is missing the document about parserPreset and parserOpts. 😦

14reactions
blackswannycommented, Apr 27, 2019

ok, i debugged and I know why we think it doesn’t work.

  1. The parser takes headerPattern and runs regex.match for commit message. Match results are put into output json under names provided in headerCorrespondence. So headerCorrespondence is a must have or nothing is saved. For instance ['type', 'reference'] https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-commits-parser/lib/parser.js image

  2. Then tools is looping through only rules and try to ask each rule if it fails against that output. If you have no rule, nothing to be caught.

https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/lint/src/index.js image

  1. However, the last thing is that we can check only against existing rules, which all expect exact fields in parser output. For instance rule type-empty expects that parsed.type should be present, which can only happen if we used headerCorrespondence: ['type']. So literally there is no custom check via this parserOpts and it totally sticks to rules of commitlint itself. So I have to use type-empty rule even if I don’t have type as my first match in commit message, but something else.
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the conventional-commits-parser.sync function in ...
To help you get started, we've selected a few conventional-commits-parser.sync examples, based on popular ways it is used in public projects.
Read more >
argparse — Parser for command-line options, arguments and ...
ArgumentParser . It is a container for argument specifications and has options that apply the parser as whole: parser = argparse.
Read more >
Customise commitlint header format - git - Stack Overflow
Right now, I've been trying a lot of things using the parserPreset , parserOpts , headerPattern and headerCorrespondence properties from ...
Read more >
conventional-commits-parser - npm
Parse raw conventional commits. Latest version: 3.2.4, last published: a year ago. Start using conventional-commits-parser in your project ...
Read more >
NetWitness Log Parser Tool User Guide - RSA Community
To create a log parser that a NetWitness Log Decoder can use to identify, ... However, you may not need to define the...
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