/commitlint-config

Arrai Innovation's shareable configuration for commitlint.

Primary LanguageJavaScriptBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

commitlint-config

Arrai Innovation's shareable configuration for commitlint.

Use with pre-commit

  1. Install pre-commit: https://pre-commit.com

  2. Install the commit-msg hook type:

    $ pre-commit install --hook-type commit-msg
    pre-commit installed at .git/hooks/commit-msg
  3. Create a .pre-commit-config.yaml file at the root of your repo:

    default_stages: [commit]
    fail_fast: true
    
    repos:
        - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
          rev: v4.1.0
          hooks:
            - id: commitlint
              stages: [ commit-msg ]
              additional_dependencies: [ "@arrai-innovations/commitlint-config" ]

    It contains a pre-commit hook for commitlint using commitlint-pre-commit-hook with this repo's configuration as a dependency.

  4. Add a .commitlintrc.json or other commitlint configuration file (see Install commitlint) to the root of your repo:

    {
        "extends": ["@arrai-innovations/commitlint-config"]
    }

Use with Husky

  1. Install Husky: https://typicode.github.io/husky/

    $ npm install --save-dev "husky@^5"
  2. Install commitlint/cli: https://www.npmjs.com/package/@commitlint/cli

    $ npm install --save-dev @commitlint/cli
  3. Create a .husky/commit-msg file at the root of your repo to run commitlint:

    #!/usr/bin/env bash
    npx --no-install commitlint --edit "$1"

    Husky changed formats in version 5. Version 4 Husky used to have it's hooks configured in package.json.

  4. Add scripts to package.json to install Husky hooks when a user runs npm install while developing our package:

    $ npm install --save-dev is-ci pinst
    {
       ...
       "scripts": {
          ...,
          "postinstall": "is-ci || husky install",
          "prepublishOnly": "pinst --disable",
          "postpublish": "pinst --enable"
       },
       ...
    }

    The is-ci module helps us not install hooks uselessly on ci builds. The pisnt module helps us not install hooks when users install this package as a dependency.

  5. Install this repo's configuration:

    $ npm install --save-dev @arrai-innovations/commitlint-config
  6. Add a .commitlintrc.json or other commitlint configuration file (see Install commitlint) to the root of your repo:

    {
        "extends": ["@arrai-innovations/commitlint-config"]
    }