Skip to content

Commit 0a635b1

Browse files
committed
style: change the style to match go Lint rule
1 parent a767625 commit 0a635b1

2 files changed

Lines changed: 32 additions & 31 deletions

File tree

commit-msg.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
)
1010

11-
func logAndExit(state MsgState, v ...interface{}) {
11+
func logAndExit(state msgState, v ...interface{}) {
1212
if state <= Merge {
1313
log.Printf(state.Hint(), v...)
1414
os.Exit(0)
@@ -49,37 +49,37 @@ func checkEmpty(str string) bool {
4949
return strings.TrimSpace(str) == ""
5050
}
5151

52-
func checkType(type_ string) {
52+
func checkType(typ string) {
5353
for _, t := range TypeList {
54-
if type_ == t {
54+
if typ == t {
5555
return
5656
}
5757
}
58-
logAndExit(WrongType, type_, Types)
58+
logAndExit(WrongType, typ, Types)
5959
}
6060

6161
func checkHeader(header string) {
6262
if checkEmpty(header) {
6363
logAndExit(EmptyHeader)
6464
}
6565

66-
re := regexp.MustCompile(HEADER_PATTERN)
66+
re := regexp.MustCompile(headerPattern)
6767
groups := re.FindStringSubmatch(header)
6868

6969
if groups == nil || checkEmpty(groups[5]) {
7070
logAndExit(BadHeaderFormat, header)
7171
}
7272

73-
type_ := groups[3]
74-
checkType(type_)
73+
typ := groups[3]
74+
checkType(typ)
7575

7676
isFixupOrSquash := (groups[2] != "")
7777
// scope := groups[4] // TODO: 根据配置对scope检查
7878
// subject := groups[5] // TODO: 根据规则对subject检查
7979

8080
length := len(header)
8181
if length > Config.LineLimit &&
82-
!(isFixupOrSquash || type_ == "revert" || type_ == "Revert") {
82+
!(isFixupOrSquash || typ == "revert" || typ == "Revert") {
8383
logAndExit(LineOverLong, length, Config.LineLimit, header)
8484
}
8585
}
@@ -110,7 +110,7 @@ func validateMsg(msg string) {
110110
logAndExit(EmptyMessage)
111111
}
112112

113-
if strings.HasPrefix(msg, MERGE_PREFIX) {
113+
if strings.HasPrefix(msg, mergePrefix) {
114114
logAndExit(Merge)
115115
}
116116

config.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,29 @@ import (
77
)
88

99
const (
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
2930
const (
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

4849
var (
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

7071
func 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
148149
more 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

Comments
 (0)