How to use parser headerPattern
See original GitHub issueThe 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:
- Created 4 years ago
- Reactions:10
- Comments:18 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is missing the document about
parserPreset
andparserOpts
. 😦ok, i debugged and I know why we think it doesn’t work.
The parser takes
headerPattern
and runsregex.match
for commit message. Match results are put into output json under names provided inheaderCorrespondence
. SoheaderCorrespondence
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.jsThen 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
type-empty
expects thatparsed.type
should be present, which can only happen if we usedheaderCorrespondence: ['type']
. So literally there is no custom check via thisparserOpts
and it totally sticks to rules of commitlint itself. So I have to usetype-empty
rule even if I don’t havetype
as my first match in commit message, but something else.