commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

Rule does not work with #ids

Open kamathgopal opened this issue 2 years ago • 12 comments

I was trying this utility in my project as we are planning to enforce conventional commit messages. It works nicely but I was pleasantly surprised when it started failing miserably. When I tried to commit with messages like git commit -m "#123 - test commit" it does not throw any error. However when I run commitlint --from=HEAD~1 it shows error.

Screenshot 2023-05-31 at 14 34 20

This is causing issues as the team is accustomed to #ticket-id - message pattern.

kamathgopal avatar May 31 '23 13:05 kamathgopal

This is causing issues as the team is accustomed to #ticket-id - message pattern.

This isn't the conventional-commits structure though, so it fails correctly.

You might be able to achieve your structure by adjusting the configuration. Please have a look at https://commitlint.js.org and the issues in this repo.

escapedcat avatar May 31 '23 13:05 escapedcat

@escapedcat my issue is commitlint is not throwing any error and accepts it as valid commit message :(

kamathgopal avatar May 31 '23 13:05 kamathgopal

Ah sorry, sounds like your husky setup might have issues.

This works for us: /.husky/commit-msg

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

yarn commitlint --edit 

How does yours look like? Have a look at the issues. We recently had some issues on how to configure husky correctly.

escapedcat avatar May 31 '23 13:05 escapedcat

I can confirm there is no issue with husky as it fires correctly before commit. We even have a pre-commit hook for linting staged files. Even commitlint works in most of the scenarios it fails only when I use commit message in above format.

Screenshot 2023-05-31 at 14 58 08

Husky setup is as below

Screenshot 2023-05-31 at 15 01 41

kamathgopal avatar May 31 '23 14:05 kamathgopal

it fails only when I use commit message in above format.

Ooohhhh, I see. I assume commitlint thinks this is a commented out sentence as does not lint it.

escapedcat avatar May 31 '23 14:05 escapedcat

Oh that was not expected :( is there a work around or will this be treated as bug? The same rule works when we run commitlint --from=HEAD~1 weird though.

kamathgopal avatar May 31 '23 14:05 kamathgopal

Uhm, nor sure. I remember there were some adjustments regarding comments in the commit-body. Would be good to have a look what was done there and if this also caused this. In general this might be a bug I guess.

escapedcat avatar May 31 '23 14:05 escapedcat

Thank you @escapedcat for your quick replies. I will continue with current setup hopefully we get a fix for this in near future :)

kamathgopal avatar May 31 '23 14:05 kamathgopal

hopefully we get a fix for this in near future

Only if someone is motivated to take care of it :P
I'll try to find the PR I mentioned.

escapedcat avatar May 31 '23 14:05 escapedcat

hopefully we get a fix for this in near future

Only if someone is motivated to take care of it :P I'll try to find the PR I mentioned.

May I offer my assistance with this Git issue, despite being new to open source? I have recently reviewed this codebase to implement custom issue prefixes. I think i might be able to help with some guidance.

FiscalCoder avatar Jun 04 '23 19:06 FiscalCoder

@kamathgopal which commitlint version are you using? According to this issue it's fixed: #3208

I just tried this with current master

echo "#123 - test commit" | ./@commitlint/cli/cli.js
â§—   input: #123 - test commit
✖   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

Update:
-m '#123 - test commit' is leading to the bug. @HoLiSchitz have a look if you have some time. #3208 might be related. #2827 as well.

Would be nice to have the same behaviour when running -m or echo "#123 - test commit" | ./@commitlint/cli/cli.js or other ways of linting.

escapedcat avatar Jun 05 '23 08:06 escapedcat

@escapedcat thanks, I am using the version 17.6.5.

kamathgopal avatar Jun 05 '23 08:06 kamathgopal