1+ const WIP_REGEX = / ^ w i p [: ] ? $ / i;
2+ const RULE_ERROR_LEVEL = 2 ;
3+ const HEADER_MAX_LENGTH = 100 ;
4+ const SUBJECT_MIN_LENGTH = 5 ;
5+
6+ module . exports = {
7+ extends : [ "@commitlint/config-conventional" ] ,
8+ rules : {
9+ "custom-subject-empty" : [ RULE_ERROR_LEVEL , "never" ] ,
10+ "custom-type-enum" : [ RULE_ERROR_LEVEL , "always" ] ,
11+ "custom-no-wip" : [ RULE_ERROR_LEVEL , "always" ] ,
12+ "custom-no-wip-subject" : [ RULE_ERROR_LEVEL , "always" ] ,
13+ "subject-min-length" : [ RULE_ERROR_LEVEL , "always" , SUBJECT_MIN_LENGTH ] ,
14+ "subject-case" : [ 0 ] , // optional: allow flexibility in subject case
15+ "header-max-length" : [ RULE_ERROR_LEVEL , "always" , HEADER_MAX_LENGTH ]
16+ } ,
17+ plugins : [
18+ {
19+ rules : {
20+ "custom-subject-empty" : ( { subject } ) =>
21+ subject && subject . trim ( ) . length > 0
22+ ? [ true ]
23+ : [
24+ false ,
25+ "The commit needs a description after the colon (:). Eg: feat: add new feature"
26+ ] ,
27+ "custom-type-enum" : ( { type } ) => {
28+ const allowedTypes = [
29+ "feat" ,
30+ "fix" ,
31+ "hotfix" ,
32+ "docs" ,
33+ "style" ,
34+ "refactor" ,
35+ "test" ,
36+ "chore"
37+ ] ;
38+
39+ if ( ! type ) {
40+ return [
41+ false ,
42+ "Missing type. Use: feat, fix, chore, refactor, etc."
43+ ] ;
44+ }
45+
46+ if ( ! allowedTypes . includes ( type ) ) {
47+ return [
48+ false ,
49+ `Type "${ type } is invalid". Allowed types: ${ allowedTypes . join (
50+ ", "
51+ ) } `
52+ ] ;
53+ }
54+
55+ return [ true ] ;
56+ } ,
57+ "custom-no-wip" : ( { header } ) => {
58+ const isWipOnly = WIP_REGEX . test ( header . trim ( ) ) ;
59+ return [
60+ ! isWipOnly ,
61+ "Commit message cannot be just \"WIP\" (use a descriptive message)."
62+ ] ;
63+ } ,
64+ "custom-no-wip-subject" : ( { subject } ) => {
65+ if ( ! subject ) return [ true ] ;
66+
67+ const isWipOnly = WIP_REGEX . test ( subject . trim ( ) ) ;
68+ return [
69+ ! isWipOnly ,
70+ "Subject cannot be just \"WIP\". Use a descriptive message like \"implement user login\" instead."
71+ ] ;
72+ }
73+ }
74+ }
75+ ]
76+ } ;
0 commit comments