Skip to content

Commit 8dcf1c1

Browse files
authored
[build] add lint for commit-msg (youzan#4164)
1 parent 89a9804 commit 8dcf1c1

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

build/lint-commit-msg.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const fs = require('fs');
2+
const signale = require('signale');
3+
4+
const gitParams = process.env.HUSKY_GIT_PARAMS;
5+
const commitMsg = fs.readFileSync(gitParams, 'utf-8').trim();
6+
7+
const commitRE = /^(revert: )?\[(fix|feat|docs|perf|test|types|build|chore|refactor|breaking change)\].{1,50}/;
8+
9+
if (!commitRE.test(commitMsg)) {
10+
signale.error(`Error: invalid commit message format.
11+
12+
Proper commit message format is required for automated changelog generation.
13+
14+
Examples:
15+
16+
[fix] Button: incorrect style
17+
[feat] Button: add color prop
18+
[dosc] Button: fix typo
19+
20+
Allowed Types:
21+
22+
- fix
23+
- feat
24+
- docs
25+
- perf
26+
- test
27+
- types
28+
- build
29+
- chore
30+
- refactor
31+
- breaking change
32+
`);
33+
process.exit(1);
34+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
},
2929
"husky": {
3030
"hooks": {
31-
"pre-commit": "lint-staged"
31+
"pre-commit": "lint-staged",
32+
"commit-msg": "node build/lint-commit-msg.js"
3233
}
3334
},
3435
"lint-staged": {

0 commit comments

Comments
 (0)