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.

commitlint ignores commit messages starting with hashtag "#"

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
kobelobstercommented, May 31, 2022

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

1reaction
kobelobstercommented, May 31, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

git - How do you configure commitlint to ignore certain commit ...
The syntax is given by the type information provided by ignores?: ((message: string) => boolean)[]; . You need to add a function that...
Read more >
support skipping linting · Issue #60 - GitHub
commitlint currently skips commits according to git semantics - meaning that merge , fixup and squash commits are ignored automatically.
Read more >
commitlint - Lint commit messages
commitlint helps your team adhere to a commit convention. By supporting npm-installed configurations it makes sharing of commit conventions easy.
Read more >
How to Write Good Commit Messages with Commitlint
Commitlint is a simple tool that lints your commit messages and makes sure they follow a set of rules. It runs as a...
Read more >
Use Smart Commits | Bitbucket Cloud - Atlassian Support
Any text between the issue key and the command is ignored. There are three commands you can use in your Smart Commit messages:...
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