Skip to content

Commit 689aa1d

Browse files
committed
style: rename some var to match the go style
1 parent 2578349 commit 689aa1d

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

commit-msg.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func logAndExit(state MsgState, v ...interface{}) {
1616
log.Fatalf(state.Hint(), v...)
1717
} else {
1818
log.Printf(state.Hint(), v...)
19-
log.Fatalf(ruleHint, strings.Join(typeList[:], ", "))
19+
log.Fatalf(RuleHint, strings.Join(TypeList[:], ", "))
2020
}
2121
}
2222

@@ -50,12 +50,12 @@ func checkEmpty(str string) bool {
5050
}
5151

5252
func checkType(type_ string) {
53-
for _, t := range typeList {
53+
for _, t := range TypeList {
5454
if type_ == t {
5555
return
5656
}
5757
}
58-
logAndExit(WrongType, type_, strings.Join(typeList[:], ", "))
58+
logAndExit(WrongType, type_, strings.Join(TypeList[:], ", "))
5959
}
6060

6161
func checkHeader(header string) {
@@ -78,15 +78,15 @@ func checkHeader(header string) {
7878
// subject := groups[5] // TODO: 根据规则对subject检查
7979

8080
length := len(header)
81-
if length > config.LineLimit &&
81+
if length > Config.LineLimit &&
8282
!(isFixupOrSquash || type_ == "revert" || type_ == "Revert") {
83-
logAndExit(LineOverLong, length, config.LineLimit, header)
83+
logAndExit(LineOverLong, length, Config.LineLimit, header)
8484
}
8585
}
8686

8787
func checkBody(body string) {
8888
if checkEmpty(body) {
89-
if config.BodyRequired {
89+
if Config.BodyRequired {
9090
logAndExit(BodyMissing)
9191
} else {
9292
logAndExit(Validated)
@@ -99,8 +99,8 @@ func checkBody(body string) {
9999

100100
for _, line := range strings.Split(body, "\n") {
101101
length := len(line)
102-
if length > config.LineLimit {
103-
logAndExit(LineOverLong, length, config.LineLimit, line)
102+
if length > Config.LineLimit {
103+
logAndExit(LineOverLong, length, Config.LineLimit, line)
104104
}
105105
}
106106
}
@@ -125,7 +125,7 @@ func validateMsg(msg string) {
125125

126126
if len(sections) == 2 {
127127
checkBody(sections[1])
128-
} else if config.BodyRequired {
128+
} else if Config.BodyRequired {
129129
logAndExit(BodyMissing)
130130
}
131131

config.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const (
1111
CONFIG_FILE = "commit-msg.cfg.json"
1212
)
1313

14-
type Config struct {
14+
type GlobalConfig struct {
1515
Lang string
1616
BodyRequired bool
1717
LineLimit int
@@ -39,10 +39,10 @@ const (
3939
)
4040

4141
var (
42-
config *Config
42+
Config *GlobalConfig
43+
RuleHint string
4344
stateHint []string
44-
ruleHint string
45-
typeList = [...]string{
45+
TypeList = [...]string{
4646
"feat", // new feature 新功能
4747
"fix", // fix bug 修复
4848
"docs", // documentation 文档
@@ -112,22 +112,22 @@ if you can not find any error after check, maybe you use Chinese colon, or lack
112112
}
113113
)
114114

115-
func loadConfig() *Config {
115+
func loadConfig() *GlobalConfig {
116116
f, err := os.Open(CONFIG_FILE)
117117
if err != nil {
118118
return nil
119119
}
120120
defer f.Close()
121121
dec := json.NewDecoder(f)
122-
var cfg Config
122+
var cfg GlobalConfig
123123
if err := dec.Decode(&cfg); err != nil {
124124
return nil
125125
}
126126
return &cfg
127127
}
128128

129-
func initConfig() *Config {
130-
cfg := &Config{"en", false, 80}
129+
func initConfig() *GlobalConfig {
130+
cfg := &GlobalConfig{"en", false, 80}
131131
f, err := os.Create(CONFIG_FILE)
132132
if err != nil {
133133
return cfg
@@ -140,18 +140,18 @@ func initConfig() *Config {
140140
}
141141

142142
func init() {
143-
config = loadConfig()
144-
if config == nil {
145-
config = initConfig()
143+
Config = loadConfig()
144+
if Config == nil {
145+
Config = initConfig()
146146
}
147147

148-
switch config.Lang {
148+
switch Config.Lang {
149149
case "zh-CN":
150150
stateHint = zhCnHint[:]
151-
ruleHint = zhCnRule
151+
RuleHint = zhCnRule
152152
default:
153153
stateHint = enHint[:]
154-
ruleHint = enRule
154+
RuleHint = enRule
155155
}
156156
}
157157

0 commit comments

Comments
 (0)