Skip to content

Commit 3e1341e

Browse files
refactor(lint): move rule validate to separate method
1 parent 5d1e1f6 commit 3e1341e

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

lint/linter.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,30 @@ func (l *Linter) LintCommit(msg *Commit) (*Result, error) {
2929
res := newResult(msg.FullCommit)
3030

3131
for _, rule := range l.rules {
32-
result, isOK := rule.Validate(msg)
33-
if !isOK {
34-
ruleConf := l.conf.GetRule(rule.Name())
35-
res.add(RuleResult{
36-
Name: rule.Name(),
37-
Severity: ruleConf.Severity,
38-
Message: result,
39-
})
32+
currentRule := rule
33+
ruleConf := l.conf.GetRule(currentRule.Name())
34+
ruleRes, isValid := l.runRule(currentRule, ruleConf.Severity, msg)
35+
if !isValid {
36+
res.add(ruleRes)
4037
}
4138
}
4239

4340
return res, nil
4441
}
4542

43+
func (l *Linter) runRule(rule Rule, severity Severity, msg *Commit) (RuleResult, bool) {
44+
ruleMsg, isOK := rule.Validate(msg)
45+
if isOK {
46+
return RuleResult{}, true
47+
}
48+
res := RuleResult{
49+
Name: rule.Name(),
50+
Severity: severity,
51+
Message: ruleMsg,
52+
}
53+
return res, false
54+
}
55+
4656
func (l *Linter) headerErrorRule(commitMsg string) *Result {
4757
// TODO: show more information
4858
res := newResult(commitMsg)

0 commit comments

Comments
 (0)