diff --git a/internal/parser/keyword/parser.go b/internal/parser/keyword/parser.go index f811010..f7a3913 100644 --- a/internal/parser/keyword/parser.go +++ b/internal/parser/keyword/parser.go @@ -8,7 +8,8 @@ import ( ) type Match struct { - Keyword string + Keywords []string + Keyword string // TODO: remove me Score int MaxMatchCount int } @@ -26,18 +27,21 @@ type Keyword struct{} func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { score := conf.Score comment := "" - for _, file := range conf.Files { - content := executorResult.Files[file] - for _, match := range conf.Matches { - count := strings.Count(content, match.Keyword) - if match.MaxMatchCount > 0 { - count = min(count, match.MaxMatchCount) + for _, match := range conf.Matches { + for _, keyword := range match.Keywords { + keywordMatchCount := 0 + for _, file := range conf.Files { + content := executorResult.Files[file] + keywordMatchCount += strings.Count(content, keyword) } - if count > 0 { - score -= count * match.Score + if match.MaxMatchCount > 0 { + keywordMatchCount = min(keywordMatchCount, match.MaxMatchCount) + } + if keywordMatchCount > 0 { + score -= keywordMatchCount * match.Score comment += fmt.Sprintf( "Matched keyword %d time(s): %s\n", - count, match.Keyword) + keywordMatchCount, keyword) } } } @@ -54,6 +58,13 @@ func (*Keyword) Run(results []stage.ExecutorResult, confAny any) ( if err != nil { return nil, true, err } + // TODO: remove me on Matches.Keyword field removed + for i := range conf.Matches { + match := &conf.Matches[i] + if match.Keyword != "" && len(match.Keywords) == 0 { + match.Keywords = []string{match.Keyword} + } + } // TODO: remove me on FullScore field removed if conf.FullScore != 0 && conf.Score == 0 { conf.Score = conf.FullScore