ParseAndLint checks the given commitMsg string against rules
(commitMsg string)
| 48 | |
| 49 | // ParseAndLint checks the given commitMsg string against rules |
| 50 | func (l *Linter) ParseAndLint(commitMsg string) (*Result, error) { |
| 51 | if l.isIgnored(commitMsg) { |
| 52 | return newResult(commitMsg), nil |
| 53 | } |
| 54 | |
| 55 | var ( |
| 56 | msg Commit |
| 57 | diagnostics []error |
| 58 | ) |
| 59 | if l.parser != nil { |
| 60 | var err error |
| 61 | msg, err = l.parser.Parse(commitMsg) |
| 62 | if err != nil { |
| 63 | diagnostics = []error{err} |
| 64 | } |
| 65 | } else { |
| 66 | msg, diagnostics = commit.Inspect(commitMsg) |
| 67 | } |
| 68 | |
| 69 | if msg != nil && len(diagnostics) == 0 { |
| 70 | return l.Lint(msg) |
| 71 | } |
| 72 | |
| 73 | var issues []*Issue |
| 74 | for _, diagnostic := range diagnostics { |
| 75 | issues = append(issues, l.parserErrorRule(commitMsg, diagnostic)...) |
| 76 | } |
| 77 | if msg == nil { |
| 78 | return newResult(commitMsg, issues...), nil |
| 79 | } |
| 80 | |
| 81 | result, err := l.Lint(msg) |
| 82 | if err != nil { |
| 83 | return nil, err |
| 84 | } |
| 85 | result.issues = append(issues, result.issues...) |
| 86 | return result, nil |
| 87 | } |
| 88 | |
| 89 | // isIgnored checks if the first line of the commit message |
| 90 | // matches any of the configured ignore patterns |