feat(parser/clangtidy): summary by category
This commit is contained in:
parent
1da16d5c45
commit
9e1ecf164b
internal/parser/clangtidy
|
@ -77,7 +77,7 @@ func isIgnored(line string) bool {
|
|||
}
|
||||
|
||||
func parseMessage(line string) ClangMessage {
|
||||
messageRegex := regexp.MustCompile(`^(?P<filepath>.+):(?P<line>\d+):(?P<column>\d+): (?P<level>\S+): (?P<message>.*?)(?: \[(?P<diagnostic_name>.*)\])?\n$`)
|
||||
messageRegex := regexp.MustCompile(`^(?P<filepath>.+):(?P<line>\d+):(?P<column>\d+): (?P<level>\S+): (?P<message>.*?) \[(?P<diagnostic_name>[^\]]+)\]?\n$`)
|
||||
regexRes := messageRegex.FindStringSubmatch(line)
|
||||
if len(regexRes) == 0 {
|
||||
return *newClangMessage("", 0, 0, UNKNOWN, "", "", nil, nil)
|
||||
|
@ -138,7 +138,7 @@ func ParseLines(lines []string, conf Conf) []ClangMessage {
|
|||
message := parseMessage(string(line))
|
||||
if message.level == UNKNOWN && len(messages) > 0 {
|
||||
messages[len(messages)-1].detailsLines = append(messages[len(messages)-1].detailsLines, string(line))
|
||||
} else {
|
||||
} else if message.level != UNKNOWN {
|
||||
messages = append(messages, message)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,60 +2,49 @@ package clangtidy
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
|
||||
score := conf.Score
|
||||
comment := "### Test results summary\n\n"
|
||||
keys := [...]string{
|
||||
"codequality-unchecked-malloc-result",
|
||||
"codequality-no-global-variables",
|
||||
"codequality-no-header-guard",
|
||||
"codequality-no-fflush-stdin",
|
||||
"readability-function-size",
|
||||
"readability-duplicate-include",
|
||||
"readability-identifier-naming",
|
||||
"readability-redundant",
|
||||
"readability-misleading-indentation",
|
||||
"readability-misplaced-array-index",
|
||||
"cppcoreguidelines-init-variables",
|
||||
"bugprone-suspicious-string-compare",
|
||||
"google-global-names-in-headers",
|
||||
"clang-diagnostic",
|
||||
"clang-analyzer",
|
||||
"misc",
|
||||
"performance",
|
||||
"others",
|
||||
}
|
||||
mapping := map[string]int{}
|
||||
for _, key := range keys {
|
||||
mapping[key] = 0
|
||||
}
|
||||
categoryCount := map[string]int{}
|
||||
for _, jsonMessage := range jsonMessages {
|
||||
// checkName is commas separated string here
|
||||
checkName := jsonMessage.CheckName
|
||||
for _, match := range conf.Matches {
|
||||
for _, keyword := range match.Keywords {
|
||||
// TODO: The keyword in json report might also be an array, need to split it
|
||||
if strings.Contains(checkName, keyword) {
|
||||
score -= match.Score
|
||||
}
|
||||
}
|
||||
}
|
||||
listed := false
|
||||
for key := range mapping {
|
||||
if strings.Contains(checkName, key) {
|
||||
mapping[key] += 1
|
||||
listed = true
|
||||
checkNames := strings.Split(checkName, ",")
|
||||
for _, checkName := range checkNames {
|
||||
parts := strings.Split(checkName, "-")
|
||||
if len(parts) > 0 {
|
||||
category := parts[0]
|
||||
categoryCount[category] += 1
|
||||
}
|
||||
}
|
||||
if !listed {
|
||||
mapping["others"] += 1
|
||||
}
|
||||
}
|
||||
|
||||
for i, key := range keys {
|
||||
comment = fmt.Sprintf("%s%d. %s: %d\n", comment, i+1, key, mapping[key])
|
||||
type kv struct {
|
||||
Key string
|
||||
Value int
|
||||
}
|
||||
var ss []kv
|
||||
for k, v := range categoryCount {
|
||||
ss = append(ss, kv{k, v})
|
||||
}
|
||||
sort.Slice(ss, func(i, j int) bool {
|
||||
if ss[i].Value == ss[j].Value {
|
||||
return ss[i].Key < ss[j].Key
|
||||
}
|
||||
return ss[i].Value > ss[j].Value
|
||||
})
|
||||
for i, kv := range ss {
|
||||
comment += fmt.Sprintf("%d. %s: %d\n", i+1, kv.Key, kv.Value)
|
||||
}
|
||||
return score, comment
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user