Skip to content

commitlint ignores commit messages starting with hashtag "#" #3208

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

Closed
2 of 4 tasks
kobelobster opened this issue May 30, 2022 · 5 comments
Closed
2 of 4 tasks

commitlint ignores commit messages starting with hashtag "#" #3208

kobelobster opened this issue May 30, 2022 · 5 comments

Comments

@kobelobster
Copy link

kobelobster commented May 30, 2022

Expected Behavior

commitlint -e fails when type is not present and a hashtag is used at the beginning of the commit message

Current Behavior

commitlint -e succeeds when omitting a type and using a hashtag at the beginning of the commit message

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

Is a # maybe interpeted as a comment, and thus succeeds?

Steps to Reproduce (for bugs)

We have a .husky/pre-commit file with the following contents

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

commitlint -e

Our .commitlintrc.json looks like this

{
  "extends": ["./node_modules/@commitlint/config-conventional"],
  "rules": {
    "subject-case": [0],
    "type-enum": [2, "always", ["feat", "fix", "chore"]],
    "header-max-length": [0, "always", 120],
    "body-max-line-length": [0, "always", "Infinity"],
    "footer-max-line-length": [0, "always", "Infinity"]
  }
}

Using this configuration, writing in CLI

git commit -m "foo: bar" leads to

$ commitlint -e
⧗   input: foo: bar
✖   type must be one of [feat, fix, chore] [type-enum]

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

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
husky - commit-msg hook exited with code 1 (error)

while git commit -m "#8299-fix-prettier" leads to

Done in 0.58s.
[feature/test 66676512] #8299-fix-prettier
 1 file changed, 111 insertions(+)
 create mode 100644 test.yml

My suspicion is that it's somehow interpeted as comment? But shouldn't it still fail, since we have the always rule case regarding the type.

Context

We are using azure devops, so in order to link workitems (tickets) to a commit, we used the commit message template #1234 Add foo before. We now switched to conventional commits and have a pre-commit hook.

However, some developers still need to adjust to these changes and accidentally commit with the wrong commit message. This shouldn't be a problem, since we have pre-commit hooks, however the pre-commit hook is not triggered when using a hashtag as a commit message

Your Environment

Executable Version
commitlint --version 13.1.0
git --version 2.32.0.windows.1
node --version v14.17.3
@escapedcat
Copy link
Member

Hey, yeah this would be a bug. I just tried this with the current version and couldn't reproduce this. Please see if updating solves this for you. If not we need to check a bit more I guess.

@kobelobster
Copy link
Author

kobelobster commented May 31, 2022

Hi @escapedcat. Thanks for your reply. I have updated to version 13.2.1 but the issue persists. I saw that v13 is EOL anyway since a week, so might be a reason to upgrade to another version.

May I ask which version you are using? You said the current version, so I'm guessing just the most up 2 date one? I would like to try the same that you are using.

@kobelobster
Copy link
Author

I just confirmed, when using 17.0.1 this issue is resolved. Commiting with a message as described now leads to an error

$ commitlint -e
⧗   input: #8299-fix-prettier
✖   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

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
husky - commit-msg hook exited with code 1 (error)

Since my bug was for an EOL version, I will close this issue as it is resolved and won't be fixed. We updated our package to version 17.0.1

@escapedcat
Copy link
Member

Yay! 🎉
tbh we also wouldn't fix such bugs in still supported versions. In these we only fix critical security issues. We don't have the manpower to provide that.

@kobelobster
Copy link
Author

Yes, makes sense! You also state that in the README.md so no worries! We now updated to v17.0.1 Thanks for this library and the quick support

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

No branches or pull requests

2 participants