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.

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 issue

Steps 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`
                    ];

...

  1. Run the plugin against a commit msg like foo: bar baz, it works.
  2. Run the plugin against a commit msg like foo.bar: baz or foo-bar: baz or foo,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:open
  • Created a year ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
AdeAttwoodcommented, Oct 3, 2022

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.

0reactions
knoctecommented, Oct 3, 2022

to achieve something similar to you and used a plugin

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.

Read more comments on GitHub >

github_iconTop 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 >

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