Just a little shareable configuration for commitlint
to be able to validate the addition of an issue number to the end of a commit message that follows the Conventional Commits specification.
The commit message structure must be:
<type>(<scope>): <description> [<issue-number>]
Where:
<type>
is mandatory<scope>
is optional<description>
is mandatory<issue-number>
is mandatory
Install commitlint
and this configuration:
npm install --save-dev @commitlint/cli @d3p1/commitlint-config
Then, extend this configuration from your commitlint
configuration object using the extends
option. For example, create in the root of your project a commitlint.config.js
file with the following content:
module.exports = {
extends: ['@d3p1/commitlint-config']
};
Also, to be able to validate your commit messages in your environment, install and configure husky
:
npm install --save-dev husky
npx husky install
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit ${1}'
Note
Starting from
husky@v9
, the initialization and installation command needs to be modified. Instead ofnpx husky install
andnpx husky add .husky/commit-msg 'npx --no -- commitlint --edit ${1}'
, usenpx husky init
andecho "npx --no -- commitlint --edit \$1" > .husky/commit-msg
.
Note
The
npx husky init
command could create apre-commit
hook (.husky/commit-msg
) that may not be needed and could cause errors. It could be removed manually. Also, instead of executingnpx husky init
andecho "npx --no -- commitlint --edit \$1" > .husky/commit-msg
, it is possible to executenpx husky
andecho "npx --no -- commitlint --edit \$1" > .husky/commit-msg
to avoid the creation of thepre-commit
hook.
And you are ready to go! From now on, all messages from your commits will be validated to ensure they adhere to the format:
<type>(<scope>): <description> [<issue-number>]
Detailed changes for each release are documented in CHANGELOG.md
.
This work is published under MIT License.
Always happy to receive a greeting on: