@@ -23,21 +23,16 @@ type TalismanRC struct {
2323 Version string `yaml:"version"`
2424}
2525
26- // SuggestRCFor returns the talismanRC file content corresponding to input ignore configs
26+ // SuggestRCFor returns a string representation of a .talismanrc for the specified FileIgnoreConfigs
2727func SuggestRCFor (configs []FileIgnoreConfig ) string {
2828 tRC := TalismanRC {FileIgnoreConfig : configs , Version : DefaultRCVersion }
2929 result , _ := yaml .Marshal (tRC )
3030
3131 return string (result )
3232}
3333
34- // Accept answers true if the Addition.Path is configured to be checked by the detectors
35- func (tRC * TalismanRC ) Accept (addition gitrepo.Addition , detectorName string ) bool {
36- return ! tRC .Deny (addition , detectorName )
37- }
38-
39- // FilterAdditions removes scope files from additions
40- func (tRC * TalismanRC ) FilterAdditions (additions []gitrepo.Addition ) []gitrepo.Addition {
34+ // RemoveScopedFiles removes scope files from additions
35+ func (tRC * TalismanRC ) RemoveScopedFiles (additions []gitrepo.Addition ) []gitrepo.Addition {
4136 var applicableScopeFileNames []string
4237 if tRC .ScopeConfig != nil {
4338 for _ , scope := range tRC .ScopeConfig {
@@ -62,6 +57,7 @@ func (tRC *TalismanRC) FilterAdditions(additions []gitrepo.Addition) []gitrepo.A
6257 return result
6358}
6459
60+ // AddIgnores inserts the specified FileIgnoreConfigs to an existing .talismanrc file, or creates one if it doesn't exist.
6561func (tRC * TalismanRC ) AddIgnores (entriesToAdd []FileIgnoreConfig ) {
6662 if len (entriesToAdd ) > 0 {
6763 logr .Debugf ("Adding entries: %v" , entriesToAdd )
@@ -112,18 +108,8 @@ func combineFileIgnores(exsiting, incoming []FileIgnoreConfig) []FileIgnoreConfi
112108 return result
113109}
114110
115- // Deny answers true if the Addition.Path is configured to be ignored and not checked by the detectors
116- func (tRC * TalismanRC ) Deny (addition gitrepo.Addition , detectorName string ) bool {
117- for _ , pattern := range tRC .effectiveRules (detectorName ) {
118- if addition .Matches (pattern ) {
119- return true
120- }
121- }
122- return false
123- }
124-
125- // Strip git addition
126- func (tRC * TalismanRC ) FilterAllowedPatternsFromAddition (addition gitrepo.Addition ) string {
111+ // RemoveAllowedPatterns removes globally- and per-file allowed patterns from an Addition
112+ func (tRC * TalismanRC ) RemoveAllowedPatterns (addition gitrepo.Addition ) string {
127113 additionPathAsString := string (addition .Path )
128114 // Processing global allowed patterns
129115 for _ , pattern := range tRC .AllowedPatterns {
@@ -141,13 +127,27 @@ func (tRC *TalismanRC) FilterAllowedPatternsFromAddition(addition gitrepo.Additi
141127 return string (addition .Data )
142128}
143129
130+ // Deny answers true if the Addition should NOT be checked by the specified detector
131+ func (tRC * TalismanRC ) Deny (addition gitrepo.Addition , detectorName string ) bool {
132+ for _ , pattern := range tRC .effectiveRules (detectorName ) {
133+ if addition .Matches (pattern ) {
134+ return true
135+ }
136+ }
137+ return false
138+ }
139+
140+ // Accept answers true if the Addition should be checked by the specified detector
141+ func (tRC * TalismanRC ) Accept (addition gitrepo.Addition , detectorName string ) bool {
142+ return ! tRC .Deny (addition , detectorName )
143+ }
144+
144145func (tRC * TalismanRC ) effectiveRules (detectorName string ) []string {
145146 var result []string
146147 for _ , ignore := range tRC .FileIgnoreConfig {
147148 if ignore .isEffective (detectorName ) {
148149 result = append (result , ignore .GetFileName ())
149150 }
150151 }
151-
152152 return result
153153}
0 commit comments