Conventional Commits
Commitlint
Install
npm install --save-dev @commitlint/cli @commitlint/config-conventional
1
commitlint.config.js
Create file 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
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
Install
npm install --save-dev yorkie
1
gitHooks
to your package.json
.
Add the {
"gitHooks": {
"commit-msg": "commitlint -e -V "
}
}
1
2
3
4
5
2
3
4
5
Lefthook
Install
npm install --save-dev @arkweid/lefthook
1
lefthook.yml
Add hooks to commit-msg:
commands:
lint-commit-msg:
run: npx --no-install commitlint --edit
1
2
3
4
2
3
4