Skip to content

Commit

Permalink
Merge pull request #104 from jmle/fix-formatting
Browse files Browse the repository at this point in the history
Fix rule formatting
  • Loading branch information
jmle authored Nov 30, 2023
2 parents e79f657 + e47feb5 commit 392e3f4
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions pkg/conversion/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 392e3f4

Please sign in to comment.