Conventional Commits

Commitlint

Install

npm install --save-dev @commitlint/cli @commitlint/config-conventional
1

Create file commitlint.config.js

const JIRA_ISSUE_REGEX = /^[A-Z]+-\d+$/g;

module.exports = {
  extends: ["@commitlint/config-conventional"],
  rules: {
    "jira-issue-in-scope": [2, "always"],
  },
  plugins: [
    {
      rules: {
        "jira-issue-in-scope": ({ scope }) => {
          const validScope =
            scope == null ||
            (typeof scope == "string" && scope.match(JIRA_ISSUE_REGEX));

          return [validScope, "Scope can only be JIRA issue"];
        },
      },
    },
  ],
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Pre-commit Hook

Deprecated

Use lefthook instead

yorkieopen in new window

Install

npm install --save-dev yorkie
1

Add the gitHooks to your package.json.

{
  "gitHooks": {
    "commit-msg": "commitlint -e -V "
  }
}
1
2
3
4
5

Lefthook

lefthookopen in new window

Install

npm install --save-dev @arkweid/lefthook
1

Add hooks to lefthook.yml

commit-msg:
  commands:
    lint-commit-msg:
      run: npx --no-install commitlint --edit
1
2
3
4