Daniele Lenares
dnlnrs.dev | A DevLog

dnlnrs.dev | A DevLog

Lint your commits

Lint your commits

The "conventional" way

Daniele Lenares's photo
Daniele Lenares
ยทApr 19, 2021ยท

2 min read

If you are using Conventional Commits (and if you don't, you should ๐Ÿ˜œ) it is very useful to have something that tells you if you are committing the right way. This topic will be focused on JavaScript projects.

As you know, conventional commits are composed this way:

type(scope?): subject

It's easy to do a commmit message that don't represent this standard so linting comes in our help!

We are going to use two packages: commitlint and husky


This package checks if the commit messages are in the form showed above, or at least in a form type: subject. It's easily configurable through file so its configuration is shareable.

module.exports = {
  extend: {

With the package installed and configured we are telling the code that we would like our commits to be "conventional". But we need to ask commitlint to lint our messages. Can we do this automatically everytime we make a new commit?


Husky is a package that interact with the hooks exposed by git to trigger some custom actions: linters, error checking, scripts running, etc... In this case we would like to trigger a commitlint check everytime we do a commit wothout the needing of launch the lint manually. Fortunately the community comes in our help and we need to launch only two commands

yarn husky install

npx husky add .husky/commit-msg 'npx --no-install commitlint --edit $1'

At the end this setup will make sure that everytime we commit, the linter gets called and all checks are made.

And if we commit without following the rules, this happens (VSCode example)


โง—   input: test commit
โœ–   subject may not be empty [subject-empty]
โœ–   type may not be empty [type-empty]

โœ–   found 2 problems, 0 warnings
Share this