From 24204b47af54f8556fc2c7673b56595d71e0d62c Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sat, 2 Nov 2024 03:36:32 -0400 Subject: [PATCH] feat(parser): support force quit on deduct --- internal/parser/clangtidy/parser.go | 20 +++++++++++++------- internal/parser/cppcheck/parser.go | 18 ++++++++++++------ internal/parser/cpplint/parser.go | 18 ++++++++++++------ 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/internal/parser/clangtidy/parser.go b/internal/parser/clangtidy/parser.go index 388715c..455e3d3 100644 --- a/internal/parser/clangtidy/parser.go +++ b/internal/parser/clangtidy/parser.go @@ -14,11 +14,12 @@ type Match struct { } type Conf struct { - Score int - RootDir string `default:"/w"` - Matches []Match - Stdout string `default:"stdout"` - Stderr string `default:"stderr"` + Score int + RootDir string `default:"/w"` + Matches []Match + Stdout string `default:"stdout"` + Stderr string `default:"stderr"` + ForceQuitOnDeduct bool `default:"false"` } type ClangTidy struct{} @@ -56,8 +57,13 @@ func (*ClangTidy) Run(results []stage.ExecutorResult, confAny any) ( return nil, true, err } var res []stage.ParserResult + forceQuit := false for _, result := range results { - res = append(res, Parse(result, *conf)) + parseRes := Parse(result, *conf) + if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score { + forceQuit = true + } + res = append(res, parseRes) } - return res, false, nil + return res, forceQuit, nil } diff --git a/internal/parser/cppcheck/parser.go b/internal/parser/cppcheck/parser.go index 514eb56..9b65194 100644 --- a/internal/parser/cppcheck/parser.go +++ b/internal/parser/cppcheck/parser.go @@ -15,10 +15,11 @@ type Match struct { } type Conf struct { - Score int - Matches []Match - Stdout string `default:"stdout"` - Stderr string `default:"stderr"` + Score int + Matches []Match + Stdout string `default:"stdout"` + Stderr string `default:"stderr"` + ForceQuitOnDeduct bool `default:"false"` } type Record struct { @@ -89,8 +90,13 @@ func (*CppCheck) Run(results []stage.ExecutorResult, confAny any) ( return nil, true, err } var res []stage.ParserResult + forceQuit := false for _, result := range results { - res = append(res, Parse(result, *conf)) + parseRes := Parse(result, *conf) + if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score { + forceQuit = true + } + res = append(res, parseRes) } - return res, false, nil + return res, forceQuit, nil } diff --git a/internal/parser/cpplint/parser.go b/internal/parser/cpplint/parser.go index bc7abdb..7498952 100644 --- a/internal/parser/cpplint/parser.go +++ b/internal/parser/cpplint/parser.go @@ -15,10 +15,11 @@ type Match struct { } type Conf struct { - Score int - Matches []Match - Stdout string `default:"stdout"` - Stderr string `default:"stderr"` + Score int + Matches []Match + Stdout string `default:"stdout"` + Stderr string `default:"stderr"` + ForceQuitOnDeduct bool `default:"false"` } type Cpplint struct{} @@ -88,8 +89,13 @@ func (*Cpplint) Run(results []stage.ExecutorResult, confAny any) ( return nil, true, err } var res []stage.ParserResult + forceQuit := false for _, result := range results { - res = append(res, Parse(result, *conf)) + parseRes := Parse(result, *conf) + if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score { + forceQuit = true + } + res = append(res, parseRes) } - return res, false, nil + return res, forceQuit, nil }