Skip to content

Commit d79e106

Browse files
committed
style: rename some functions
1 parent 3b704dd commit d79e106

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

validator/validate.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ func validateMsg(msg string, config *globalConfig) {
6969

7070
sections := strings.SplitN(msg, "\n", 2)
7171

72-
checkHeader(sections[0], config)
72+
validateHeader(sections[0], config)
7373

7474
if len(sections) == 2 {
75-
checkBody(sections[1], config)
75+
validateBody(sections[1], config)
7676
} else if config.BodyRequired {
7777
state.BodyMissing.LogAndExit()
7878
}
@@ -86,11 +86,14 @@ func isEmpty(str string) bool {
8686

8787
func isMergeCommit(msg string) {
8888
if strings.HasPrefix(msg, mergePrefix) {
89+
// merge commit is auto generated by git or other tool,
90+
// cannot be modified in most cases.
91+
// just skip the rest validation.
8992
state.Merge.LogAndExit()
9093
}
9194
}
9295

93-
func checkHeader(header string, config *globalConfig) {
96+
func validateHeader(header string, config *globalConfig) {
9497
if isEmpty(header) {
9598
state.EmptyHeader.LogAndExit()
9699
}
@@ -109,11 +112,11 @@ func checkHeader(header string, config *globalConfig) {
109112
}
110113

111114
typ := groups[3]
112-
checkType(typ)
115+
validateType(typ)
113116

114117
isFixupOrSquash := (groups[2] != "")
115118

116-
checkScope(groups[4], config)
119+
validateScope(groups[4], config)
117120

118121
// TODO: 根据规则对subject检查
119122
// subject := groups[5]
@@ -131,7 +134,7 @@ func isRevertHeader(header string) bool {
131134
return m
132135
}
133136

134-
func checkType(typ string) {
137+
func validateType(typ string) {
135138
for t := range TypeSet {
136139
if typ == t {
137140
return
@@ -140,7 +143,7 @@ func checkType(typ string) {
140143
state.WrongType.LogAndExit(typ, TypesStr)
141144
}
142145

143-
func checkScope(scope string, config *globalConfig) {
146+
func validateScope(scope string, config *globalConfig) {
144147
if isEmpty(scope) {
145148
if config.ScopeRequired {
146149
state.ScopeMissing.LogAndExit()
@@ -160,7 +163,7 @@ func checkScope(scope string, config *globalConfig) {
160163
state.WrongScope.LogAndExit(scope, strings.Join(config.Scopes, ", "))
161164
}
162165

163-
func checkBody(body string, config *globalConfig) {
166+
func validateBody(body string, config *globalConfig) {
164167
if isEmpty(body) {
165168
if config.BodyRequired {
166169
state.BodyMissing.LogAndExit()

validator/validate_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestGetMsg(t *testing.T) {
6868
}, "Normal", 0)
6969
}
7070

71-
func TestCheckEmpty(t *testing.T) {
71+
func TestValidateEmpty(t *testing.T) {
7272
var emptyCases = []struct {
7373
text string
7474
want bool
@@ -88,21 +88,21 @@ func TestCheckEmpty(t *testing.T) {
8888
}
8989
}
9090

91-
func TestCheckType(t *testing.T) {
91+
func TestValidateType(t *testing.T) {
9292
assertExitCode(t, func() {
93-
checkType("feat")
93+
validateType("feat")
9494
}, "feat", 0)
9595

9696
assertExitCode(t, func() {
97-
checkType("")
97+
validateType("")
9898
}, "no_type", int(state.WrongType))
9999

100100
assertExitCode(t, func() {
101-
checkType("Feat")
101+
validateType("Feat")
102102
}, "wrong_type", int(state.WrongType))
103103
}
104104

105-
func TestCheckHeader(t *testing.T) {
105+
func TestValidateHeader(t *testing.T) {
106106
var headerCases = []struct {
107107
text string
108108
name string
@@ -122,12 +122,12 @@ func TestCheckHeader(t *testing.T) {
122122
}
123123
for _, tt := range headerCases {
124124
assertExitCode(t, func() {
125-
checkHeader(tt.text, tt.config)
125+
validateHeader(tt.text, tt.config)
126126
}, tt.name, tt.want)
127127
}
128128
}
129129

130-
func TestCheckBody(t *testing.T) {
130+
func TestValidateBody(t *testing.T) {
131131
var bodyCases = []struct {
132132
text string
133133
name string
@@ -142,7 +142,7 @@ func TestCheckBody(t *testing.T) {
142142
}
143143
for _, tt := range bodyCases {
144144
assertExitCode(t, func() {
145-
checkBody(tt.text, tt.config)
145+
validateBody(tt.text, tt.config)
146146
}, tt.name, tt.want)
147147
}
148148
}
@@ -165,7 +165,7 @@ This reverts commit 1234567890abcdef1234567890abcdef12345678.`, defaultCfg)
165165
}, "Revert", 0)
166166
}
167167

168-
func TestCheckScope(t *testing.T) {
168+
func TestValidateScope(t *testing.T) {
169169
var scopeCases = []struct {
170170
text string
171171
name string
@@ -180,7 +180,7 @@ func TestCheckScope(t *testing.T) {
180180
}
181181
for _, tt := range scopeCases {
182182
assertExitCode(t, func() {
183-
checkScope(tt.text, tt.config)
183+
validateScope(tt.text, tt.config)
184184
}, tt.name, tt.want)
185185
}
186186
}

0 commit comments

Comments
 (0)