Add lint check for footer-like lines outside footer.
Change-Id: I2b7941b5cdec7c2634a22bc48c564c5c159a507f
diff --git a/lint/lint.go b/lint/lint.go
index 01a760b..9d8a208 100644
--- a/lint/lint.go
+++ b/lint/lint.go
@@ -146,6 +146,7 @@
var fixesIssueRegexp = regexp.MustCompile("(?i)^fixes issue [0-9]{3,}[.]?$")
var issueRegexp = regexp.MustCompile("(?i)issue [0-9]{3,}")
+var footerRegexp = regexp.MustCompile("^[A-Za-z0-9-]+:")
func (l *linter) checkMessage(commitmsg []string) {
warn := func(line int, message string) {
@@ -171,11 +172,22 @@
}
}
- for i := len(commitmsg) - 1; i >= 0 && len(commitmsg[i]) > 0; i-- {
- if commitmsg[i][0] == ' ' {
+ // Note: don't check subject line
+ for i, inFooter := len(commitmsg)-1, true; i >= 1; i-- {
+ if len(commitmsg[i]) == 0 {
+ inFooter = false
continue
}
- field := strings.TrimSpace(strings.Split(commitmsg[i], ":")[0])
+ if !footerRegexp.MatchString(commitmsg[i]) {
+ if inFooter {
+ warn(i+1, "Footer lines should be separated from message body by a blank line.")
+ }
+ break
+ }
+ if !inFooter {
+ warn(i+1, "Footer lines should form a single paragraph (i.e. must not be separated by blank lines.)")
+ }
+ field := strings.SplitN(commitmsg[i], ":", 2)[0]
if field != strings.Title(field) {
warn(i+1, "Footer fields should be in Title-Case.")
break
diff --git a/lint/lint_test.go b/lint/lint_test.go
index 515a39a..857c0ed 100644
--- a/lint/lint_test.go
+++ b/lint/lint_test.go
@@ -113,6 +113,43 @@
},
},
},
+ {
+ message: []string{
+ "Topic: Subject line looking like footer line",
+ "",
+ "Change-Id: blah",
+ },
+ // No warnings
+ },
+ {
+ message: []string{
+ "Subject line",
+ "",
+ "Message body",
+ "Change-Id: blah",
+ },
+ warnings: []gerrit.Comment{
+ gerrit.Comment{
+ Line: 9,
+ Message: "[warning] Footer lines should be separated from message body by a blank line.",
+ },
+ },
+ },
+ {
+ message: []string{
+ "Subject line",
+ "",
+ "Bug: issue 8403",
+ "",
+ "Change-Id: blah",
+ },
+ warnings: []gerrit.Comment{
+ gerrit.Comment{
+ Line: 9,
+ Message: "[warning] Footer lines should form a single paragraph (i.e. must not be separated by blank lines.)",
+ },
+ },
+ },
}
for _, test := range tests {