All checks were successful
continuous-integration/drone/push Build is passing
Co-authored-by: zjc_he <zjc_he@sjtu.edu.cn> Reviewed-on: FOCS-dev/JOJ3#26 Reviewed-by: 张泊明518370910136 <bomingzh@sjtu.edu.cn> Co-authored-by: 张佳澈520370910044 <zjc_he@sjtu.edu.cn> Co-committed-by: 张佳澈520370910044 <zjc_he@sjtu.edu.cn>
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package clangtidy
|
|
|
|
import (
|
|
"fmt"
|
|
"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 `default:"100"`
|
|
RootDir string `default:"/w"`
|
|
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 := ParseLines(lines, conf)
|
|
formattedMessages := Format(messages)
|
|
|
|
if executorResult.Status != stage.Status(envexec.StatusAccepted) {
|
|
if !((executorResult.Status == stage.Status(envexec.StatusNonzeroExitStatus)) &&
|
|
(executorResult.ExitStatus == 1)) {
|
|
return stage.ParserResult{
|
|
Score: 0,
|
|
Comment: fmt.Sprintf(
|
|
"Unexpected executor status: %s.\nStderr: %s",
|
|
executorResult.Status, stderr,
|
|
),
|
|
}
|
|
}
|
|
}
|
|
return stage.ParserResult{
|
|
Score: GetScore(formattedMessages, conf),
|
|
Comment: GetComment(formattedMessages),
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|