feat(parser): backward compatibility
This commit is contained in:
parent
24204b47af
commit
4db6f556c6
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
type Match struct {
|
type Match struct {
|
||||||
Keywords []string
|
Keywords []string
|
||||||
|
Severity []string // TODO: remove me
|
||||||
Score int
|
Score int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package cppcheck
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,10 +19,54 @@ const (
|
||||||
UNKNOWN
|
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) {
|
func GetResult(records []Record, conf Conf) (string, int, error) {
|
||||||
result := "### Test results summary\n\n"
|
result := "### Test results summary\n\n"
|
||||||
var severityCounts [UNKNOWN + 1]int
|
var severityCounts [UNKNOWN + 1]int
|
||||||
score := conf.Score
|
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 _, record := range records {
|
||||||
for _, match := range conf.Matches {
|
for _, match := range conf.Matches {
|
||||||
for _, keyword := range match.Keywords {
|
for _, keyword := range match.Keywords {
|
||||||
|
|
|
@ -2,7 +2,9 @@ package cpplint
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||||
|
@ -44,14 +46,18 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||||
// }
|
// }
|
||||||
// message := match[3]
|
// message := match[3]
|
||||||
category := match[4]
|
category := match[4]
|
||||||
// confidence, err := strconv.Atoi(match[5])
|
// TODO: remove me
|
||||||
// if err != nil {
|
if len(conf.Matches) == 0 {
|
||||||
// slog.Error("parse confidence", "error", err)
|
confidence, err := strconv.Atoi(match[5])
|
||||||
// return stage.ParserResult{
|
if err != nil {
|
||||||
// Score: 0,
|
slog.Error("parse confidence", "error", err)
|
||||||
// Comment: fmt.Sprintf("Unexpected parser error: %s.", err),
|
return stage.ParserResult{
|
||||||
// }
|
Score: 0,
|
||||||
// }
|
Comment: fmt.Sprintf("Unexpected parser error: %s.", err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
score -= confidence
|
||||||
|
}
|
||||||
for _, match := range conf.Matches {
|
for _, match := range conf.Matches {
|
||||||
for _, keyword := range match.Keywords {
|
for _, keyword := range match.Keywords {
|
||||||
if strings.Contains(category, keyword) {
|
if strings.Contains(category, keyword) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user