fix: typo
All checks were successful
submodules sync / sync (push) Successful in 1m13s
build / build (push) Successful in 3m16s
build / trigger-build-image (push) Successful in 11s

This commit is contained in:
张泊明518370910136 2025-10-07 21:27:22 -07:00
parent 1c70191ea8
commit 341ab39435
GPG Key ID: D47306D7062CDA9D

View File

@ -18,29 +18,29 @@ type Record struct {
} }
// monkey patch for not escaped " in cppcheck message // monkey patch for not escaped " in cppcheck message
func (*CppCheck) fixStderr(stderr string) string { func (*CppCheck) fixLine(line string) string {
const prefixMarker = `"message":"` const prefixMarker = `"message":"`
const suffixMarker = `", "id":"` const suffixMarker = `", "id":"`
prefixIndex := strings.Index(stderr, prefixMarker) prefixIndex := strings.Index(line, prefixMarker)
if prefixIndex == -1 { if prefixIndex == -1 {
return stderr return line
} }
contentStartIndex := prefixIndex + len(prefixMarker) contentStartIndex := prefixIndex + len(prefixMarker)
suffixIndex := strings.LastIndex(stderr, suffixMarker) suffixIndex := strings.LastIndex(line, suffixMarker)
if suffixIndex == -1 || suffixIndex < contentStartIndex { if suffixIndex == -1 || suffixIndex < contentStartIndex {
return stderr return line
} }
contentEndIndex := suffixIndex contentEndIndex := suffixIndex
prefix := stderr[:contentStartIndex] prefix := line[:contentStartIndex]
messageContent := stderr[contentStartIndex:contentEndIndex] messageContent := line[contentStartIndex:contentEndIndex]
suffix := stderr[contentEndIndex:] suffix := line[contentEndIndex:]
cleanedMessageContent := strings.ReplaceAll(messageContent, `"`, `\"`) cleanedMessageContent := strings.ReplaceAll(messageContent, `"`, `\"`)
return prefix + cleanedMessageContent + suffix return prefix + cleanedMessageContent + suffix
} }
func (p *CppCheck) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { func (p *CppCheck) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
// stdout := executorResult.Files[conf.Stdout] // stdout := executorResult.Files[conf.Stdout]
stderr := p.fixStderr(executorResult.Files[conf.Stderr]) stderr := executorResult.Files[conf.Stderr]
records := make([]Record, 0) records := make([]Record, 0)
lines := strings.SplitSeq(stderr, "\n") lines := strings.SplitSeq(stderr, "\n")
for line := range lines { for line := range lines {
@ -48,7 +48,7 @@ func (p *CppCheck) parse(executorResult stage.ExecutorResult, conf Conf) stage.P
continue continue
} }
var record Record var record Record
err := json.Unmarshal([]byte(line), &record) err := json.Unmarshal([]byte(p.fixLine(line)), &record)
if err != nil { if err != nil {
return stage.ParserResult{ return stage.ParserResult{
Score: 0, Score: 0,