feat(parser/clangtidy): summary by category
This commit is contained in:
parent
1da16d5c45
commit
9e1ecf164b
|
@ -77,7 +77,7 @@ func isIgnored(line string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseMessage(line string) ClangMessage {
|
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)
|
regexRes := messageRegex.FindStringSubmatch(line)
|
||||||
if len(regexRes) == 0 {
|
if len(regexRes) == 0 {
|
||||||
return *newClangMessage("", 0, 0, UNKNOWN, "", "", nil, nil)
|
return *newClangMessage("", 0, 0, UNKNOWN, "", "", nil, nil)
|
||||||
|
@ -138,7 +138,7 @@ func ParseLines(lines []string, conf Conf) []ClangMessage {
|
||||||
message := parseMessage(string(line))
|
message := parseMessage(string(line))
|
||||||
if message.level == UNKNOWN && len(messages) > 0 {
|
if message.level == UNKNOWN && len(messages) > 0 {
|
||||||
messages[len(messages)-1].detailsLines = append(messages[len(messages)-1].detailsLines, string(line))
|
messages[len(messages)-1].detailsLines = append(messages[len(messages)-1].detailsLines, string(line))
|
||||||
} else {
|
} else if message.level != UNKNOWN {
|
||||||
messages = append(messages, message)
|
messages = append(messages, message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,60 +2,49 @@ package clangtidy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
|
func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
|
||||||
score := conf.Score
|
score := conf.Score
|
||||||
comment := "### Test results summary\n\n"
|
comment := "### Test results summary\n\n"
|
||||||
keys := [...]string{
|
categoryCount := map[string]int{}
|
||||||
"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
|
|
||||||
}
|
|
||||||
for _, jsonMessage := range jsonMessages {
|
for _, jsonMessage := range jsonMessages {
|
||||||
|
// checkName is commas separated string here
|
||||||
checkName := jsonMessage.CheckName
|
checkName := jsonMessage.CheckName
|
||||||
for _, match := range conf.Matches {
|
for _, match := range conf.Matches {
|
||||||
for _, keyword := range match.Keywords {
|
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) {
|
if strings.Contains(checkName, keyword) {
|
||||||
score -= match.Score
|
score -= match.Score
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
listed := false
|
checkNames := strings.Split(checkName, ",")
|
||||||
for key := range mapping {
|
for _, checkName := range checkNames {
|
||||||
if strings.Contains(checkName, key) {
|
parts := strings.Split(checkName, "-")
|
||||||
mapping[key] += 1
|
if len(parts) > 0 {
|
||||||
listed = true
|
category := parts[0]
|
||||||
|
categoryCount[category] += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !listed {
|
|
||||||
mapping["others"] += 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
type kv struct {
|
||||||
for i, key := range keys {
|
Key string
|
||||||
comment = fmt.Sprintf("%s%d. %s: %d\n", comment, i+1, key, mapping[key])
|
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
|
return score, comment
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user