feat(rule): validate & sort rule when generating (#1817)

This commit is contained in:
Richard Gomez authored and GitHub committed 2025-04-12 10:09:19 -05:00
1 parent 107a41827b
commit cfdeb0d7e0
18 files changed
+145 -115

No files matched your search

+6 -8
View File
@@ -67,7 +67,7 @@ type Config struct {
Path string
Description string
Rules map[string]Rule
Allowlist Allowlist
Allowlist *Allowlist
Keywords map[string]struct{}
// used to keep sarif results consistent
@@ -164,17 +164,15 @@ func (vc *ViperConfig) Translate() (Config, error) {
allowlistPaths = append(allowlistPaths, regexp.MustCompile(a))
}
allowlist := Allowlist{
allowlist := &Allowlist{
Description: a.Description,
MatchCondition: condition,
Commits: a.Commits,
Paths: allowlistPaths,
RegexTarget: a.RegexTarget,
Regexes: allowlistRegexes,
Paths: allowlistPaths,
Commits: a.Commits,
StopWords: a.StopWords,
}
if err := allowlist.Validate(); err != nil {
return Config{}, fmt.Errorf("%s: %w", cr.RuleID, err)
}
cr.Allowlists = append(cr.Allowlists, allowlist)
}
orderedRules = append(orderedRules, cr.RuleID)
@@ -192,7 +190,7 @@ func (vc *ViperConfig) Translate() (Config, error) {
Description: vc.Description,
Extend: vc.Extend,
Rules: rulesMap,
Allowlist: Allowlist{
Allowlist: &Allowlist{
RegexTarget: vc.Allowlist.RegexTarget,
Regexes: allowlistRegexes,
Paths: allowlistPaths,