MCPcopy Create free account
hub / github.com/conventionalcommit/commitlint / ParseAndLint

Method ParseAndLint

lint/linter.go:50–87  ·  view source on GitHub ↗

ParseAndLint checks the given commitMsg string against rules

(commitMsg string)

Source from the content-addressed store, hash-verified

48
49// ParseAndLint checks the given commitMsg string against rules
50func (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

Calls 6

isIgnoredMethod · 0.95
LintMethod · 0.95
parserErrorRuleMethod · 0.95
InspectFunction · 0.92
newResultFunction · 0.85
ParseMethod · 0.65