From e47feb5b097bef8b50054fbddee4200eea838991 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Wed, 29 Nov 2023 21:42:42 +0100 Subject: [PATCH] Do not concatenate lines in descs; do not concatenate desc & message; some cleanup Signed-off-by: Juan Manuel Leflet Estrada --- pkg/conversion/convert.go | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/pkg/conversion/convert.go b/pkg/conversion/convert.go index 7825ef4..2d41bfb 100644 --- a/pkg/conversion/convert.go +++ b/pkg/conversion/convert.go @@ -167,14 +167,8 @@ func ConvertWindupRulesetToAnalyzer(ruleset windup.Ruleset) []map[string]interfa if perform["category"] != nil { rule["category"] = perform["category"] } - description := "" if perform["message"] != nil { rule["message"] = perform["message"] - // if message doesn't contain a template, add it to the description too - if msg, ok := perform["message"].(string); ok && - !strings.Contains(msg, "{{") { - description = msg - } } if perform["labels"] != nil { if performLabels, ok := perform["labels"].([]string); ok { @@ -192,17 +186,7 @@ func ConvertWindupRulesetToAnalyzer(ruleset windup.Ruleset) []map[string]interfa if perform["effort"] != nil { rule["effort"] = perform["effort"] } - if perform["description"] != nil { - if dsc, ok := perform["description"].(string); ok { - description = strings.Join([]string{dsc, description}, "\n") - } - } - if description != "" { - rule["description"] = description - } - // for k, v := range perform { - // rule[k] = v - // } + rule["description"] = perform["description"] } else { continue } @@ -775,11 +759,6 @@ func convertWindupPerformToAnalyzer(perform windup.Iteration, where map[string]s } if perform.Hint != nil { - if len(perform.Hint) != 1 { - // TODO - panic("More than one hint in a rule") - return nil - } hint := perform.Hint[0] if hint.Message != "" { message := trimMessage(hint.Message) @@ -876,15 +855,8 @@ func substituteWhere(where map[string]string, pattern string) string { } func trimMessage(s string) string { - lines := strings.Split(s, "\n") - cleanLines := []string{} - for _, line := range lines { - cleaned := strings.Trim(line, "\n \t '") - if cleaned != "" { - cleanLines = append(cleanLines, cleaned) - } - } - return strings.Join(cleanLines, ". ") + re := regexp.MustCompile(`( ){2,}`) + return re.ReplaceAllString(s, " ") } func flattenWhere(wheres []windup.Where) map[string]string {