In a commit title "foo: bar baz", the text "bar baz" is considered a **subject**, but not if the text "foo" contains special chars
See original GitHub issueSteps to Reproduce (for bugs)
Develop a local plugin like documented here: https://github.com/conventional-changelog/commitlint/blob/master/docs/reference-plugins.md#local-plugins So the config file starts like this:
module.exports = {
parserPreset: 'conventional-changelog-conventionalcommits',
rules: {
'body-leading-blank': [1, 'always'],
'footer-leading-blank': [1, 'always'],
'footer-max-line-length': [2, 'always', 150],
'header-max-length': [2, 'always', 50],
'subject-full-stop': [2, 'never', '.'],
'type-empty': [1, 'never'],
'type-space-after-colon': [2, 'always'],
'subject-lowercase': [2, 'always'],
},
plugins: [
{
rules: {
'subject-lowercase': ({subject}) => {
if (subject === null || subject === undefined) {
// otherwise, String(null) might give us the stupid string "null"
throw new Error('Unexpected subject===null or subject===undefined happened');
}
let offence = false;
if (subject != null && subject.length > 1) {
let firstIsUpperCase = subject[0].toUpperCase() == subject[0];
let firstIsLowerCase = subject[0].toLowerCase() == subject[0];
let secondIsUpperCase = subject[1].toUpperCase() == subject[1];
let secondIsLowerCase = subject[1].toLowerCase() == subject[1];
offence = firstIsUpperCase && (!firstIsLowerCase)
// to whitelist acronyms
&& (!secondIsUpperCase) && secondIsLowerCase;
}
return [
!offence,
`Please use lowercase as the first letter for your subject, i.e. the text after your area/scope`
];
...
- Run the plugin against a commit msg like
foo: bar baz
, it works. - Run the plugin against a commit msg like
foo.bar: baz
orfoo-bar: baz
orfoo,bar: baz
, then…
Current Behavior
It crashes with “Unexpected subject===null or subject===undefined happened” because of the assertion.
Expected Behavior
It should not crash. Subject should always be the text after the first colon.
Affected packages
- cli
- core
- prompt
- config-angular
Possible Solution
No idea, didn’t yet dive in the source code of commitlint sorry.
Your Environment
Executable | Version |
---|---|
commitlint --version |
17.1.2 |
git --version |
2.37.3 |
node --version |
v16.17.0 |
Issue Analytics
- State:
- Created a year ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Error when using a type that has a dash ("-") [bug] · Issue #2694
commitlint should accept types with dashes in them. Current Behavior. It gives the errors "subject may not be empty" and "type may not...
Read more >git-log Documentation - Git
git log foo bar ^baz. means "list all the commits which are reachable from foo or bar, but not from baz". A special...
Read more >How to use a special character as a normal one in Unix shells?
That very much depends on the shell. Check your shell manual for details. Also note that some characters are only special in some...
Read more >Ubuntu Manpage: git-log - Show commit logs
Thus, the following command: $ git log foo bar ^baz means "list all the commits which are reachable from foo or bar, but...
Read more >perlre(1) — perl-doc — Debian buster
$foo =~ m/abc/. This evaluates to true if and only if the string in the variable $foo contains somewhere in it, the sequence...
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
Hi all, it’s been a while.
This is defo the parser regex. I still have an upstream bug outstanding to amend the regex. I would suggest changing the parser regex, here is an example for fixing a
-
in the subject https://github.com/conventional-changelog/commitlint/issues/2694#issuecomment-888536943.I detected this bug when using a plugin. My workaround was to use
{header}
instead of{subject}
; this way I extract the subject myself inside my local plugin.