JOJ3/internal/parsers/clang_tidy/parser.go
张佳澈520370910044 e133b13a84
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
feat(internal/executors/clang_tidy,-internal/parsers/clang_tidy,-cmd/joj3/main_test.go): Parsers and executors for clang-tidy
2024-05-01 00:18:09 +08:00

70 lines
1.5 KiB
Go

package clang_tidy
import (
"encoding/json"
"fmt"
"os"
"strings"
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
"github.com/criyle/go-judge/envexec"
)
type Match struct {
Keyword []string
Score int
}
type Conf struct {
Score int
Matches []Match
}
type ClangTidy struct{}
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
stdout := executorResult.Files["stdout"]
stderr := executorResult.Files["stderr"]
lines := strings.SplitAfter(stdout, "\n")
messages := parse_lines(lines)
formatted_messages := format(messages)
// TODO: Handle the json file (parse into markdown and delete it?)
json_file, _ := os.Create("./clangtidy_result.json")
defer json_file.Close()
encoder := json.NewEncoder(json_file)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ")
_ = encoder.Encode(formatted_messages)
if executorResult.Status != stage.Status(envexec.StatusAccepted) {
return stage.ParserResult{
Score: 0,
Comment: fmt.Sprintf(
"Unexpected executor status: %s.\nStderr: %s",
executorResult.Status, stderr,
),
}
}
return stage.ParserResult{
Score: get_score(formatted_messages, conf),
Comment: "",
}
}
func (*ClangTidy) Run(results []stage.ExecutorResult, confAny any) (
[]stage.ParserResult, bool, error,
) {
conf, err := stage.DecodeConf[Conf](confAny)
if err != nil {
return nil, true, err
}
var res []stage.ParserResult
for _, result := range results {
res = append(res, Parse(result, *conf))
}
return res, false, nil
}