feat(report): allow user-defined templates (#1650)

This commit is contained in:
Richard Gomez authored and GitHub committed 2024-12-10 18:56:11 -06:00
1 parent e393d299bc
commit 83e99bacf1
72 files changed
+586 -549

No files matched your search

+8 -8
View File
@@ -111,7 +111,7 @@ func (vc *ViperConfig) Translate() (Config, error) {
configPathRegex = regexp.MustCompile(vr.Path)
}
rule := Rule{
cr := Rule{
RuleID: vr.ID,
Description: vr.Description,
Regex: configRegex,
@@ -124,7 +124,7 @@ func (vc *ViperConfig) Translate() (Config, error) {
// Parse the allowlist, including the older format for backwards compatibility.
if vr.AllowList != nil {
if len(vr.Allowlists) > 0 {
return Config{}, fmt.Errorf("%s: [rules.allowlist] is deprecated, it cannot be used alongside [[rules.allowlist]]", rule.RuleID)
return Config{}, fmt.Errorf("%s: [rules.allowlist] is deprecated, it cannot be used alongside [[rules.allowlist]]", cr.RuleID)
}
vr.Allowlists = append(vr.Allowlists, *vr.AllowList)
}
@@ -137,7 +137,7 @@ func (vc *ViperConfig) Translate() (Config, error) {
case "", "OR", "||":
condition = AllowlistMatchOr
default:
return Config{}, fmt.Errorf("%s: unknown allowlist condition '%s' (expected 'and', 'or')", rule.RuleID, c)
return Config{}, fmt.Errorf("%s: unknown allowlist condition '%s' (expected 'and', 'or')", cr.RuleID, c)
}
// Validate the target.
@@ -148,7 +148,7 @@ func (vc *ViperConfig) Translate() (Config, error) {
case "match", "line":
// do nothing
default:
return Config{}, fmt.Errorf("%s: unknown allowlist |regexTarget| '%s' (expected 'match', 'line')", rule.RuleID, a.RegexTarget)
return Config{}, fmt.Errorf("%s: unknown allowlist |regexTarget| '%s' (expected 'match', 'line')", cr.RuleID, a.RegexTarget)
}
}
var allowlistRegexes []*regexp.Regexp
@@ -169,12 +169,12 @@ func (vc *ViperConfig) Translate() (Config, error) {
StopWords: a.StopWords,
}
if err := allowlist.Validate(); err != nil {
return Config{}, fmt.Errorf("%s: %w", rule.RuleID, err)
return Config{}, fmt.Errorf("%s: %w", cr.RuleID, err)
}
rule.Allowlists = append(rule.Allowlists, allowlist)
cr.Allowlists = append(cr.Allowlists, allowlist)
}
orderedRules = append(orderedRules, rule.RuleID)
rulesMap[rule.RuleID] = rule
orderedRules = append(orderedRules, cr.RuleID)
rulesMap[cr.RuleID] = cr
}
var allowlistRegexes []*regexp.Regexp
for _, a := range vc.Allowlist.Regexes {
+2 -1
View File
@@ -2,10 +2,11 @@ package config
import (
"fmt"
"github.com/google/go-cmp/cmp"
"regexp"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"