Search code examples
angularhuskygit-huskycommitlint

How to add husky and commitlint to angular project


I'd like to use huksy and commitlint to my angular project.

How can I achieve this ?


Solution

  • Install Husky

    1. Run npm i husky --save-dev
    2. Run npx husky init

    The init command simplifies setting up husky in a project. It creates a pre-commit script in .husky/ and updates the prepare script in package.json. Modifications can be made later to suit your workflow. Husky doc

    Install commitlint

    1. Run npm i @commitlint/cli @commitlint/config-conventional --save-dev
    2. Create a commitlint.config.js file at the root of the project.
    module.exports = {
      extends: ['@commitlint/config-conventional'],
    };
    
    1. in the .husky folder, add commit-msg file
    npx --no-install commitlint --edit "$1"
    
    1. (optional) remove the pre-commit file if you do not have any test

    Test it

    1. Just commit something, ex: git commit -m "Keep calm and commit"

    ENOENT: no such file .../COMMIT_EDITMSG ?

    Just open the .git folder and add an empty COMMIT_EDITMSG file.
    Git needs it to know the title you're trying to type, maybe he doesn't have the access to create the file.