feat(parser/keyword): force quit on deduct #75
|  | @ -14,21 +14,18 @@ type Match struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Conf struct { | type Conf struct { | ||||||
| 	Score            int | 	Score             int | ||||||
| 	FullScore        int // TODO: remove me
 | 	FullScore         int // TODO: remove me
 | ||||||
| 	Files            []string | 	Files             []string | ||||||
| 	ForceQuitOnMatch bool | 	ForceQuitOnDeduct bool `default:"false"` | ||||||
| 	Matches          []Match | 	Matches           []Match | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Keyword struct{} | type Keyword struct{} | ||||||
| 
 | 
 | ||||||
| func Parse(executorResult stage.ExecutorResult, conf Conf) ( | func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { | ||||||
| 	stage.ParserResult, bool, |  | ||||||
| ) { |  | ||||||
| 	score := conf.Score | 	score := conf.Score | ||||||
| 	comment := "" | 	comment := "" | ||||||
| 	matched := false |  | ||||||
| 	for _, file := range conf.Files { | 	for _, file := range conf.Files { | ||||||
| 		content := executorResult.Files[file] | 		content := executorResult.Files[file] | ||||||
| 		for _, match := range conf.Matches { | 		for _, match := range conf.Matches { | ||||||
|  | @ -37,7 +34,6 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) ( | ||||||
| 				count = min(count, match.MaxMatchCount) | 				count = min(count, match.MaxMatchCount) | ||||||
| 			} | 			} | ||||||
| 			if count > 0 { | 			if count > 0 { | ||||||
| 				matched = true |  | ||||||
| 				score -= count * match.Score | 				score -= count * match.Score | ||||||
| 				comment += fmt.Sprintf( | 				comment += fmt.Sprintf( | ||||||
| 					"Matched keyword %d time(s): %s\n", | 					"Matched keyword %d time(s): %s\n", | ||||||
|  | @ -48,7 +44,7 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) ( | ||||||
| 	return stage.ParserResult{ | 	return stage.ParserResult{ | ||||||
| 		Score:   score, | 		Score:   score, | ||||||
| 		Comment: comment, | 		Comment: comment, | ||||||
| 	}, matched | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (*Keyword) Run(results []stage.ExecutorResult, confAny any) ( | func (*Keyword) Run(results []stage.ExecutorResult, confAny any) ( | ||||||
|  | @ -65,11 +61,11 @@ func (*Keyword) Run(results []stage.ExecutorResult, confAny any) ( | ||||||
| 	var res []stage.ParserResult | 	var res []stage.ParserResult | ||||||
| 	forceQuit := false | 	forceQuit := false | ||||||
| 	for _, result := range results { | 	for _, result := range results { | ||||||
| 		tmp, matched := Parse(result, *conf) | 		parseRes := Parse(result, *conf) | ||||||
| 		if matched && conf.ForceQuitOnMatch { | 		if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score { | ||||||
| 			forceQuit = true | 			forceQuit = true | ||||||
| 		} | 		} | ||||||
| 		res = append(res, tmp) | 		res = append(res, parseRes) | ||||||
| 	} | 	} | ||||||
| 	return res, forceQuit, nil | 	return res, forceQuit, nil | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user