feat(parser): backward compatibility
All checks were successful
build / build (push) Successful in 1m53s
build / build (pull_request) Successful in 1m52s
build / trigger-build-image (push) Has been skipped
build / trigger-build-image (pull_request) Has been skipped

This commit is contained in:
张泊明518370910136 2024-11-02 04:26:01 -04:00
parent 24204b47af
commit 4db6f556c6
GPG Key ID: D47306D7062CDA9D
3 changed files with 60 additions and 8 deletions

View File

@ -11,6 +11,7 @@ import (
type Match struct {
Keywords []string
Severity []string // TODO: remove me
Score int
}

View File

@ -2,6 +2,7 @@ package cppcheck
import (
"fmt"
"log/slog"
"strings"
)
@ -18,10 +19,54 @@ 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) {
result := "### Test results summary\n\n"
var severityCounts [UNKNOWN + 1]int
score := conf.Score
// TODO: remove me
if len(conf.Matches) == 0 {
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
}
}
for _, record := range records {
severity, err := severityFromString(record.Severity)
if err != nil {
slog.Error("parse severity", "error", err)
}
severityCounts[int(severity)] += 1
score -= severityScore[int(severity)]
}
}
for _, record := range records {
for _, match := range conf.Matches {
for _, keyword := range match.Keywords {

View File

@ -2,7 +2,9 @@ package cpplint
import (
"fmt"
"log/slog"
"regexp"
"strconv"
"strings"
"github.com/joint-online-judge/JOJ3/internal/stage"
@ -44,14 +46,18 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
// }
// message := match[3]
category := match[4]
// confidence, err := strconv.Atoi(match[5])
// if err != nil {
// slog.Error("parse confidence", "error", err)
// return stage.ParserResult{
// Score: 0,
// Comment: fmt.Sprintf("Unexpected parser error: %s.", err),
// }
// }
// TODO: remove me
if len(conf.Matches) == 0 {
confidence, err := strconv.Atoi(match[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
}
for _, match := range conf.Matches {
for _, keyword := range match.Keywords {
if strings.Contains(category, keyword) {