@@ -7,28 +7,29 @@ import (
77)
88
99const (
10- MERGE_PREFIX = `Merge `
11- HEADER_PATTERN = `^((fixup! |squash! )?(\w+)(?:\(([^\)\s]+)\))?: (.+))(?:\n|$)`
12- CONFIG_FILE_NAME = "commit-msg.cfg.json"
13- HOOK_DIR = "./.git/hooks/"
10+ mergePrefix = `Merge `
11+ headerPattern = `^((fixup! |squash! )?(\w+)(?:\(([^\)\s]+)\))?: (.+))(?:\n|$)`
12+ configFileName = "commit-msg.cfg.json"
13+ hookDir = "./.git/hooks/"
1414)
1515
16- type GlobalConfig struct {
16+ type globalConfig struct {
1717 Lang string
1818 BodyRequired bool
1919 LineLimit int
2020}
2121
22- type LangPack struct {
22+ type langPack struct {
2323 HintList []string
2424 Rule string
2525}
2626
27- type MsgState int
27+ type msgState int
2828
29+ // message states
2930const (
3031 // normal state
31- Validated MsgState = iota
32+ Validated msgState = iota
3233 Merge
3334 // non format error
3435 ArgumentMissing
@@ -46,8 +47,8 @@ const (
4647)
4748
4849var (
49- Config * GlobalConfig
50- Lang * LangPack
50+ Config * globalConfig
51+ Lang * langPack
5152 TypeList = [... ]string {
5253 "feat" , // new feature 新功能
5354 "fix" , // fix bug 修复
@@ -63,35 +64,35 @@ var (
6364 Types = strings .Join (TypeList [:], ", " )
6465)
6566
66- func (state MsgState ) Hint () string {
67+ func (state msgState ) Hint () string {
6768 return Lang .HintList [state ]
6869}
6970
7071func locateConfig () string {
71- f , err := os .Stat (HOOK_DIR )
72+ f , err := os .Stat (hookDir )
7273 if err != nil || ! f .IsDir () {
73- return CONFIG_FILE_NAME
74+ return configFileName
7475 }
75- return HOOK_DIR + CONFIG_FILE_NAME
76+ return hookDir + configFileName
7677}
7778
78- func loadConfig (path string ) * GlobalConfig {
79+ func loadConfig (path string ) * globalConfig {
7980 f , err := os .Open (path )
8081 if err != nil {
8182 return nil
8283 }
8384 defer f .Close ()
8485
8586 dec := json .NewDecoder (f )
86- cfg := GlobalConfig {"en" , false , 80 }
87+ cfg := globalConfig {"en" , false , 80 }
8788 if err := dec .Decode (& cfg ); err != nil {
8889 return nil
8990 }
9091 return & cfg
9192}
9293
93- func initConfig (path string ) * GlobalConfig {
94- cfg := & GlobalConfig {"en" , false , 80 }
94+ func initConfig (path string ) * globalConfig {
95+ cfg := & globalConfig {"en" , false , 80 }
9596 f , err := os .Create (path )
9697 if err != nil {
9798 return cfg
@@ -118,7 +119,7 @@ func init() {
118119 }
119120}
120121
121- func initLangEn () * LangPack {
122+ func initLangEn () * langPack {
122123 hint := []string {
123124 "Validated: commit message meet the rule.\n " ,
124125 "Merge: merge commit detected,skip check.\n " ,
@@ -146,10 +147,10 @@ if you can not find any error after check, maybe you use Chinese colon, or lack
146147(<scope>), <body> and <footer> are optional
147148<type> must be one of %s
148149more specific instructions, please refer to: https://github.com/JayceChant/commit-msg.go`
149- return & LangPack {hint , rule }
150+ return & langPack {hint , rule }
150151}
151152
152- func initLangZhCn () * LangPack {
153+ func initLangZhCn () * langPack {
153154 hint := []string {
154155 "Validated: 提交信息符合规范。\n " ,
155156 "Merge: 合并提交,跳过规范检查。\n " ,
@@ -177,5 +178,5 @@ func initLangZhCn() *LangPack {
177178(<scope>), <body> 和 <footer> 可选
178179<type> 必须是关键字 %s 之一
179180更多信息,请参考项目主页: https://github.com/JayceChant/commit-msg.go`
180- return & LangPack {hint , rule }
181+ return & langPack {hint , rule }
181182}
0 commit comments