Skip to content

Commit 773c7d1

Browse files
committed
feat: add custom commitlint rule
1 parent 296948c commit 773c7d1

File tree

5 files changed

+1395
-1
lines changed

5 files changed

+1395
-1
lines changed

.husky/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.husky/commit-msg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
npx --no-install commitlint --edit

commitlint.config.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
plugins: ['commitlint-plugin-function-rules'],
4+
rules: {
5+
'type-empty': [0],
6+
'subject-empty': [0],
7+
'type-enum': [0],
8+
'function-rules/type-enum': [
9+
2,
10+
'always',
11+
parsed => {
12+
/**
13+
* for @commitlint/cli@^12.1.1
14+
* parsed.type would be null when meeting message with # in the type.
15+
* for example, feat#123: add a feature
16+
* parsed.type would be null, also for subject. So, I turn off
17+
* type-empty, subject-empty, type-enum...
18+
*/
19+
const headerRegex = /(((feat|fix|perf)(#\d+)?)|(build|chore|ci|docs|refactor|revert|style|test)): .+/
20+
const isHeaderValid = parsed.header.match(headerRegex)
21+
if (isHeaderValid) {
22+
return [true]
23+
}
24+
return [false, `header must match this regex: ${headerRegex}`]
25+
}
26+
]
27+
}
28+
}

0 commit comments

Comments
 (0)