JOJ3/internal/parsers/clang_tidy/parser.go
张佳澈520370910044 b0f3c880d5
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
fix(internal/parsers/clang_tidy/parser.go): Fix typo in default root dir
2024-05-07 15:38:05 +08:00

58 lines
1.3 KiB
Go

package clang_tidy
import (
"strings"
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
)
type Match struct {
Keyword []string
Score int
}
type Conf struct {
Score int `default:"100"`
RootDir string `default:"/w"`
Matches []Match
}
type ClangTidy struct{}
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
stdout := executorResult.Files["stdout"]
lines := strings.SplitAfter(stdout, "\n")
messages := parse_lines(lines, conf)
formatted_messages := format(messages)
// TODO: Handle unexpected errors from executor
// 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: get_comment(formatted_messages),
}
}
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
}