feat(parser): unify parsers conf #74
|  | @ -11,6 +11,7 @@ import ( | |||
| 
 | ||||
| type Match struct { | ||||
| 	Keywords []string | ||||
| 	Severity []string // TODO: remove me
 | ||||
| 	Score    int | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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 { | ||||
|  |  | |||
|  | @ -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) { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user