Skip to content

Instantly share code, notes, and snippets.

@pskfyi
Last active April 20, 2021 08:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pskfyi/497fbcc10a0625c716d30995fe336947 to your computer and use it in GitHub Desktop.
Save pskfyi/497fbcc10a0625c716d30995fe336947 to your computer and use it in GitHub Desktop.
Setting up Commitlint + Husky

This Gist was updated for Husky 6 in April of 2021.

You should select a commitlint config. This example uses my config, @pskfyi/commitlint-config. For the sake of simplicity, the example also assumes you're using Yarn.

Install dev dependencies:

yarn add -D husky @commitlint/cli @pskfyi/commitlint-config

Initilialize Husky:

npm set-script prepare "husky install"
yarn prepare

Create commit-msg hook in Husky that runs commitlint.

yarn husky add .husky/commit-msg "yarn commitlint --edit $1"

Create a commitlint.config.js at the root of your package or repo:

module.exports = {
  extends: ['@pskfyi/commitlint-config'], // or your chosen config
  rules: { 
    // customize rules if desired
  }
}

See the rules reference for details on how to configure further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment