refactor(comments): Clean up formatting

Clean up formatting of the comments and simplify it.

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2021-09-11 23:20:35 +02:00
parent f800164085
commit 53deef6627
No known key found for this signature in database
GPG key ID: 332171FADF1DB90B

View file

@ -13,16 +13,14 @@ func GetSeparatorForMultiline(config *Config) string {
if config.Language.OpeningOnSeparateLine { if config.Language.OpeningOnSeparateLine {
return "\n" return "\n"
} }
return " " return ""
} }
func FormatComment(config *Config, body string, beenWrapped bool) string { func FormatComment(config *Config, body string, beenWrapped bool) string {
if beenWrapped && !config.Language.OpeningOnSeparateLine { if beenWrapped && !config.Language.OpeningOnSeparateLine {
body = " " + strings.TrimPrefix(body, " "+config.Language.Continuation) body = strings.TrimPrefix(body, config.Language.Continuation)
}
if !beenWrapped && !config.Language.OpeningOnSeparateLine && !strings.HasSuffix(body, "\n") {
body = body + "\n"
} }
body = strings.TrimRightFunc(body, unicode.IsSpace)
return fmt.Sprintf("%s%s%s", config.Language.Opening, body, config.Language.Closing) return fmt.Sprintf("%s%s%s", config.Language.Opening, body, config.Language.Closing)
} }
@ -32,8 +30,6 @@ func ProcessComment(config *Config, wrapper *wrap.Wrapper, comment *gitea.PullRe
beenWrapped := len(body)+len(config.Language.Opening)+len(config.Language.Closing) > 100 beenWrapped := len(body)+len(config.Language.Opening)+len(config.Language.Closing) > 100
if beenWrapped { if beenWrapped {
body = GetSeparatorForMultiline(config) + wrapper.Wrap(body, 100) body = GetSeparatorForMultiline(config) + wrapper.Wrap(body, 100)
} else {
body = " " + body
} }
body = strings.Replace(body, "\r", "", -1) body = strings.Replace(body, "\r", "", -1)