chore(parser): remove unused conf parts
This commit is contained in:
parent
a82f8eb90c
commit
a6353dfed8
|
@ -10,7 +10,6 @@ import (
|
|||
|
||||
type Match struct {
|
||||
Keywords []string
|
||||
Severity []string // TODO: remove me
|
||||
Score int
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package cppcheck
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
@ -20,68 +19,9 @@ const (
|
|||
UNKNOWN
|
||||
)
|
||||
|
||||
func severityFromString(severityString string) (Severity, error) {
|
||||
switch severityString {
|
||||
case "error":
|
||||
return ERROR, nil
|
||||
case "warning":
|
||||
return WARNING, nil
|
||||
case "portability":
|
||||
return PORTABILITY, nil
|
||||
case "performance":
|
||||
return PERFORMANCE, nil
|
||||
case "style":
|
||||
return STYLE, nil
|
||||
case "information":
|
||||
return INFORMATION, nil
|
||||
case "debug":
|
||||
return DEBUG, nil
|
||||
default:
|
||||
return UNKNOWN, fmt.Errorf("unknown severity type \"%s\" for cppcheck", severityString)
|
||||
}
|
||||
}
|
||||
|
||||
func GetResult(records []Record, conf Conf) (string, int, error) {
|
||||
score := conf.Score
|
||||
comment := "### Test results summary\n\n"
|
||||
var severityCounts [UNKNOWN + 1]int
|
||||
// TODO: remove me
|
||||
var severityScore [UNKNOWN + 1]int
|
||||
for _, match := range conf.Matches {
|
||||
severities := match.Severity
|
||||
score := match.Score
|
||||
for _, severityString := range severities {
|
||||
severity, err := severityFromString(severityString)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
severityScore[int(severity)] = score
|
||||
}
|
||||
}
|
||||
totalSeverityScore := 0
|
||||
for _, score := range severityScore {
|
||||
totalSeverityScore += score
|
||||
}
|
||||
if totalSeverityScore != 0 {
|
||||
for _, record := range records {
|
||||
if record.File == "nofile" {
|
||||
continue
|
||||
}
|
||||
severity, err := severityFromString(record.Severity)
|
||||
if err != nil {
|
||||
slog.Error("parse severity", "error", err)
|
||||
}
|
||||
severityCounts[int(severity)] += 1
|
||||
score -= severityScore[int(severity)]
|
||||
}
|
||||
comment += fmt.Sprintf("1. error: %d\n", severityCounts[0])
|
||||
comment += fmt.Sprintf("2. warning: %d\n", severityCounts[1])
|
||||
comment += fmt.Sprintf("3. portability: %d\n", severityCounts[2])
|
||||
comment += fmt.Sprintf("4. performance: %d\n", severityCounts[3])
|
||||
comment += fmt.Sprintf("5. style: %d\n", severityCounts[4])
|
||||
comment += fmt.Sprintf("6. information: %d\n", severityCounts[5])
|
||||
comment += fmt.Sprintf("7. debug: %d\n", severityCounts[6])
|
||||
}
|
||||
matchCount := make(map[string]int)
|
||||
scoreChange := make(map[string]int)
|
||||
for _, record := range records {
|
||||
|
|
|
@ -2,14 +2,11 @@ package cpplint
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||
"github.com/joint-online-judge/JOJ3/pkg/utils"
|
||||
)
|
||||
|
||||
type Match struct {
|
||||
|
@ -34,7 +31,6 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
|||
regexMatches := re.FindAllStringSubmatch(stderr, -1)
|
||||
score := conf.Score
|
||||
comment := "### Test results summary\n\n"
|
||||
categoryCount := make(map[string]int)
|
||||
matchCount := make(map[string]int)
|
||||
scoreChange := make(map[string]int)
|
||||
for _, regexMatch := range regexMatches {
|
||||
|
@ -49,24 +45,6 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
|||
// }
|
||||
// message := regexMatch[3]
|
||||
category := regexMatch[4]
|
||||
// TODO: remove me
|
||||
if len(conf.Matches) == 0 {
|
||||
confidence, err := strconv.Atoi(regexMatch[5])
|
||||
if err != nil {
|
||||
slog.Error("parse confidence", "error", err)
|
||||
return stage.ParserResult{
|
||||
Score: 0,
|
||||
Comment: fmt.Sprintf("Unexpected parser error: %s.", err),
|
||||
}
|
||||
}
|
||||
score -= confidence
|
||||
}
|
||||
parts := strings.Split(category, "/")
|
||||
if len(parts) > 0 {
|
||||
category := parts[0]
|
||||
categoryCount[category] += 1
|
||||
}
|
||||
// TODO: remove me ends
|
||||
for _, match := range conf.Matches {
|
||||
for _, keyword := range match.Keywords {
|
||||
if strings.Contains(category, keyword) {
|
||||
|
@ -77,18 +55,6 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
|||
}
|
||||
}
|
||||
}
|
||||
// TODO: remove me
|
||||
sortedMap := utils.SortMap(categoryCount,
|
||||
func(i, j utils.Pair[string, int]) bool {
|
||||
if i.Value == j.Value {
|
||||
return i.Key < j.Key
|
||||
}
|
||||
return i.Value > j.Value
|
||||
})
|
||||
for i, kv := range sortedMap {
|
||||
comment += fmt.Sprintf("%d. %s: %d\n", i+1, kv.Key, kv.Value)
|
||||
}
|
||||
// TODO: remove me ends
|
||||
type Result struct {
|
||||
Keyword string
|
||||
Count int
|
||||
|
|
|
@ -10,14 +10,12 @@ import (
|
|||
|
||||
type Match struct {
|
||||
Keywords []string
|
||||
Keyword string // TODO: remove me
|
||||
Score int
|
||||
MaxMatchCount int
|
||||
}
|
||||
|
||||
type Conf struct {
|
||||
Score int
|
||||
FullScore int // TODO: remove me
|
||||
Files []string
|
||||
ForceQuitOnDeduct bool `default:"false"`
|
||||
Matches []Match
|
||||
|
@ -83,17 +81,6 @@ func (*Keyword) Run(results []stage.ExecutorResult, confAny any) (
|
|||
if err != nil {
|
||||
return nil, true, err
|
||||
}
|
||||
// TODO: remove me on Matches.Keyword field removed
|
||||
for i := range conf.Matches {
|
||||
match := &conf.Matches[i]
|
||||
if match.Keyword != "" && len(match.Keywords) == 0 {
|
||||
match.Keywords = []string{match.Keyword}
|
||||
}
|
||||
}
|
||||
// TODO: remove me on FullScore field removed
|
||||
if conf.FullScore != 0 && conf.Score == 0 {
|
||||
conf.Score = conf.FullScore
|
||||
}
|
||||
var res []stage.ParserResult
|
||||
forceQuit := false
|
||||
for _, result := range results {
|
||||
|
|
Loading…
Reference in New Issue
Block a user