Skip to content

Error message if colon is missed is highly misleading #3045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 4 tasks
RosieBaish opened this issue Feb 23, 2022 · 8 comments
Open
1 of 4 tasks

Error message if colon is missed is highly misleading #3045

RosieBaish opened this issue Feb 23, 2022 · 8 comments

Comments

@RosieBaish
Copy link

RosieBaish commented Feb 23, 2022

If you type a commit message but forget the colon after the type you get the error messages [subject-empty] and [type-empty] which are highly misleading.
It might be obvious to an expert user, but to a casual user it really wasn't.

Expected Behavior

echo "test(foo)

bar" | npx --no-install commitlint -V
⧗ input: test(foo)

bar
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]
W warning - missing colon after scope [missing-colon]

✖ found 2 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

Current Behavior

echo "test(foo)

bar" | npx --no-install commitlint -V
⧗ input: test(foo)

bar
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]

✖ found 2 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

An additional warning message for any commit which matches the following

  • Missing one or both of subject and type
  • First non-whitespace character of second word is not ':' or '('
  • If first non-whitespace character of second word is '(' then first non-whitespace character after matching ')' is not ':'

Steps to Reproduce (for bugs)

rvb@rosie-laptop:~/standby$ echo "test(foo)

bar" | npx --no-install commitlint -V
⧗ input: test(foo)

bar
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]

✖ found 2 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

$ echo "test(foo) bar

desc" | npx --no-install commitlint -V
⧗ input: test(foo) bar

desc
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]

✖ found 2 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

$ echo "test(foo): bar

desc" | npx --no-install commitlint -V
⧗ input: test(foo): bar
✔ found 0 problems, 0 warnings

Your Environment

npx --no-install commitlint -v
@commitlint/[email protected]

$ uname -a
Linux <removed> 5.13.0-30-generic #33~20.04.1-Ubuntu SMP Mon Feb 7 14:25:10 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.4 LTS"

Executable Version
commitlint --version @commitlint/[email protected]
git --version git version 2.25.1
node --version git version 2.25.1
@RosieBaish RosieBaish changed the title Error message if colon is missed is highly missleading Error message if colon is missed is highly misleading Feb 23, 2022
@RosieBaish
Copy link
Author

RosieBaish commented Feb 23, 2022

With the caveat that I'm not a javascript dev so this code will almost certainly need a rewrite.
I implemented a function that does the check I have in mind.
I'm fairly sure there's a better way to match for type and scope than [a-zA-Z]* but I don't know what.

function missing_colon_check(parsed, when = 'always', value = '')
{
  const {type, subject, header} = parsed;

  if (!(type === null && subject === null)) {
    // We have either a scope or subject so this check isn't required.
    return [true, "Check not required"];
  }

  //[a-zA-Z]* will match the type, this matches if the first non-whitespace character is '('
  const has_scope = header.match(/^[a-zA-Z]*\s*\(/)

  var has_colon;
  if (has_scope) {
    // First [a-zA-Z]* matches type, second matches scope. Whole regex matches if first non-whitespace character after the close bracket is ':'
    has_colon = header.match(/^[a-zA-Z]*\s*\([a-zA-Z]*\)\s*:/);
  } else {
    // [a-zA-Z]* matches type, whole regex matches if first non-whitespace character is ':'
    has_colon = header.match(/^[a-zA-Z]*\s*:/);
  }

  // Coerce to bool
  has_colon = !!has_colon;

  return [has_colon, has_colon ? "" : "Did you miss the colon?"]
}

@escapedcat
Copy link
Member

Thanks for opening this @RosieBaish
You're right, this could be improved. Doubt we have time to look into this atm though.

@rahmatkurniawantiket
Copy link

I also face the same issue

git commit -m "feat: hello world" 
⧗   input: this commit nvalid
✖   subject may not be empty [subject-empty]
✖   type may not be empty [type-empty]

✖   found 2 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

husky - pre-commit hook exited with code 1 (error)

Using the default config

{
  "extends": ["@commitlint/config-conventional"]
}

@escapedcat
Copy link
Member

@rahmatkurniawantiket this is a differnt issue I believe. Might be similar/related to this: #3492 (comment)

Can you try if this works for you?:

git commit -m 'feat: hello world'

@slav-getov
Copy link

This was only resolved in my case/experience when I did 'feat(whatevertexthere): whatevertexhere'.

@elcozy
Copy link

elcozy commented Feb 12, 2024

hello @escapedcat , any update made on this pls?

@rahmatkurniawantiket
Copy link

@escapedcat have tried both not working

@escapedcat
Copy link
Member

@rahmatkurniawantiket I do believe yours is a different issue than this. This issue is about missing a colon, yours seems to ti be different, yes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants