From f0349a461b00c0a0002fcbce5c3b130b98109a88 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sun, 3 Nov 2024 01:20:50 -0500 Subject: [PATCH] fix(parser/cppcheck): backward compatibility --- .gitmodules | 4 ++++ examples/cppcheck/simple | 1 + internal/parser/cppcheck/score.go | 26 +++++++++++++++----------- 3 files changed, 20 insertions(+), 11 deletions(-) create mode 160000 examples/cppcheck/simple diff --git a/.gitmodules b/.gitmodules index d62e72d..195d0a0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -70,3 +70,7 @@ path = examples/keyword/script url = ssh://git@focs.ji.sjtu.edu.cn:2222/JOJ/JOJ3-examples.git branch = keyword/script +[submodule "examples/cppcheck/simple"] + path = examples/cppcheck/simple + url = ssh://git@focs.ji.sjtu.edu.cn:2222/JOJ/JOJ3-examples.git + branch = cppcheck/simple diff --git a/examples/cppcheck/simple b/examples/cppcheck/simple new file mode 160000 index 0000000..e740770 --- /dev/null +++ b/examples/cppcheck/simple @@ -0,0 +1 @@ +Subproject commit e740770605acd5a003db18afde1b1e829fd2bfec diff --git a/internal/parser/cppcheck/score.go b/internal/parser/cppcheck/score.go index 6b380ab..8ac6ddb 100644 --- a/internal/parser/cppcheck/score.go +++ b/internal/parser/cppcheck/score.go @@ -45,19 +45,23 @@ func GetResult(records []Record, conf Conf) (string, int, error) { 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 + 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 } + } + totalSeverityScore := 0 + for _, score := range severityScore { + totalSeverityScore += score + } + if totalSeverityScore != 0 { for _, record := range records { severity, err := severityFromString(record.Severity) if err != nil {