@@ -23,43 +23,42 @@ func New(conf *Config, rules []Rule) (*Linter, error) {
2323func (l * Linter ) Lint (commitMsg string ) (* Result , error ) {
2424 msg , err := l .parser .Parse (commitMsg )
2525 if err != nil {
26- return l .parserErrorRule (commitMsg , err )
26+ issues := l .parserErrorRule (commitMsg , err )
27+ return newResult (commitMsg , issues ... ), nil
2728 }
2829 return l .LintCommit (msg )
2930}
3031
3132// LintCommit checks the given Commit against rules
3233func (l * Linter ) LintCommit (msg Commit ) (* Result , error ) {
33- res := newResult ( msg . Message ( ))
34+ issues := make ([] * Issue , 0 , len ( l . rules ))
3435
3536 for _ , rule := range l .rules {
3637 currentRule := rule
3738 severity := l .conf .GetSeverity (currentRule .Name ())
38- ruleRes , isValid := l .runRule (currentRule , severity , msg )
39+ issue , isValid := l .runRule (currentRule , severity , msg )
3940 if ! isValid {
40- res . add ( ruleRes )
41+ issues = append ( issues , issue )
4142 }
4243 }
4344
44- return res , nil
45+ return newResult ( msg . Message (), issues ... ) , nil
4546}
4647
4748func (l * Linter ) runRule (rule Rule , severity Severity , msg Commit ) (* Issue , bool ) {
48- failMsgs , isOK := rule .Validate (msg )
49- if isOK {
49+ issue , isValid := rule .Validate (msg )
50+ if isValid {
5051 return nil , true
5152 }
52- res := newIssue (rule .Name (), failMsgs , severity )
53- return res , false
54- }
55-
56- func (l * Linter ) parserErrorRule (commitMsg string , err error ) (* Result , error ) {
57- res := newResult (commitMsg )
5853
59- errMsg := err . Error ()
60-
61- ruleFail := newIssue ( "parser" , [] string { errMsg }, SeverityError )
62- res . add ( ruleFail )
54+ issue . ruleName = rule . Name ()
55+ issue . severity = severity
56+ return issue , false
57+ }
6358
64- return res , nil
59+ func (l * Linter ) parserErrorRule (commitMsg string , err error ) []* Issue {
60+ issue := NewIssue (err .Error ())
61+ issue .ruleName = "parser"
62+ issue .severity = SeverityError
63+ return []* Issue {issue }
6564}
0 commit comments