dev-build-deploy / commit-it

Conventional Commits library
0 stars 1 forks source link

Ignore comments on the commit message #32

Open adrianlzt opened 5 months ago

adrianlzt commented 5 months ago

I think comments (lines starting with #) should be ignored by the parser.

➜ echo -e "foo: bar\n# comment" > MSG ; python -mpre_commit hook-impl --config=.pre-commit-config.yaml --hook-type=commit-msg --hook-dir /var/tmp/tmp.WtDrdMZqn8/.git/hooks -- MSG
CommitMe - Conventional Commit message validation........................Failed
- hook id: commit-me
- exit code: 1

(node:724770) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
HEAD:1:0: error: Commits MUST be prefixed with a type, which consists of a noun, feat, fix, etc., followed by the OPTIONAL scope, OPTIONAL !, and REQUIRED terminal colon and space.

  1 | foo: bar
# comment
    | ^

HEAD:1:0: error: Commits MUST be prefixed with a type, which consists of a noun, feat, fix, etc., followed by the OPTIONAL scope, OPTIONAL !, and REQUIRED terminal colon and space.

  1 | foo: bar
# comment
    | ^

❌ Found 2 Conventional Commit compliance issues.
Kevin-de-Jong commented 5 months ago

Addressed in commit-it, will be released with commit-me before the end of the week.

adrianlzt commented 5 months ago

Can we leave the issue open until the new release of commit-me?

Kevin-de-Jong commented 5 months ago

Of course, and if possible, I would love to get feedback once deployed before closing

Kevin-de-Jong commented 5 months ago

CommitMe@v1.3.0 introduces behavior equal to git when comparing commit messages fromString() (i.e. when a message is passed via PreCommit hook or validation of Pull Requests).

In essence, any line starting with # will be removed (read: not replaced by an empty line), as is according to git specifications.

In your example;

foo: bar
# comment

this would lead to:

foo: bar

However, it is important to mention that the following example will be considered non-compliant with the Conventional Commit specification:

foo: bar
# comment
commit message subject

As it will translate to:

foo: bar
commit message subject

which does not provide an empty line between subject and body;

A longer commit body MAY be provided after the short description, providing additional contextual information about the code changes. The body MUST begin one blank line after the description.

Kevin-de-Jong commented 5 months ago

Let me know if this is satisfactory @adrianlzt

adrianlzt commented 5 months ago

That will work with git in verbose mode?

Verbose mode add lines at the end not prefixed with '#', but are ignored in the commit message.

Kevin-de-Jong commented 5 months ago

Out of curiosity, any particular (practical) use case that you are thinking of @adrianlzt ?

adrianlzt commented 5 months ago

I always use "git commit -v" (in fact, I have it configured in ~/.gitconfig), so if it does not know how to ignore those diff lines, they linter will surely not pass.

adrianlzt commented 4 months ago

Any update on this?