| 22 | func (r *BodyLeadingBlankRule) Name() string { return "body-leading-blank" } |
| 23 | func (r *BodyLeadingBlankRule) Apply(_ lint.RuleSetting) error { return nil } |
| 24 | func (r *BodyLeadingBlankRule) Validate(msg lint.Commit) (*lint.Issue, bool) { |
| 25 | body := msg.Body() |
| 26 | if body == "" { |
| 27 | return nil, true |
| 28 | } |
| 29 | // The full message should have "\n\n" separating header from body. |
| 30 | raw := msg.Message() |
| 31 | headerEnd := strings.Index(raw, "\n") |
| 32 | if headerEnd == -1 { |
| 33 | // No newline at all, body is non-empty but raw message has no newline; |
| 34 | // treat as no leading blank. |
| 35 | return lint.NewIssue("body must have a leading blank line"), false |
| 36 | } |
| 37 | rest := raw[headerEnd:] |
| 38 | if strings.HasPrefix(rest, "\n\n") { |
| 39 | return nil, true |
| 40 | } |
| 41 | return lint.NewIssue("body must have a leading blank line"), false |
| 42 | } |
| 43 | |
| 44 | // FooterLeadingBlankRule checks that when a footer is present, it begins with a blank line |
| 45 | // (i.e. there is an empty line between body/header and footer). |