mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-28 20:24:22 +01:00
handle goimports/go vet warnings
This commit is contained in:
1 parent
57d2d345b6
commit
8b70e7fc2f
12 files changed
+178
-127
No files matched your search
+2
-8
@@ -22,15 +22,9 @@ func (a *Allowlist) CommitAllowed(c string) bool {
|
||||
}
|
||||
|
||||
func (a *Allowlist) PathAllowed(path string) bool {
|
||||
if anyRegexMatch(path, a.Paths) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return anyRegexMatch(path, a.Paths)
|
||||
}
|
||||
|
||||
func (a *Allowlist) RegexAllowed(s string) bool {
|
||||
if anyRegexMatch(s, a.Regexes) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return anyRegexMatch(s, a.Regexes)
|
||||
}
|
||||
@@ -103,7 +103,10 @@ func TestTranslate(t *testing.T) {
|
||||
}
|
||||
|
||||
var vc ViperConfig
|
||||
viper.Unmarshal(&vc)
|
||||
err = viper.Unmarshal(&vc)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cfg, err := vc.Translate()
|
||||
if tt.wantError != nil {
|
||||
if err == nil {
|
||||
|
||||
@@ -14,10 +14,3 @@ type Rule struct {
|
||||
Tags []string
|
||||
Allowlist Allowlist
|
||||
}
|
||||
|
||||
func (r *Rule) EntropySet() bool {
|
||||
if r.Entropy == 0.0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"math"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
@@ -23,38 +22,3 @@ func regexMatched(f string, re *regexp.Regexp) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func containsDigit(s string) bool {
|
||||
for _, c := range s {
|
||||
switch c {
|
||||
case '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// shannonEntropy calculates the entropy of data using the formula defined here:
|
||||
// https://en.wiktionary.org/wiki/Shannon_entropy
|
||||
// Another way to think about what this is doing is calculating the number of bits
|
||||
// needed to on average encode the data. So, the higher the entropy, the more random the data, the
|
||||
// more bits needed to encode that data.
|
||||
func shannonEntropy(data string) (entropy float64) {
|
||||
if data == "" {
|
||||
return 0
|
||||
}
|
||||
|
||||
charCounts := make(map[rune]int)
|
||||
for _, char := range data {
|
||||
charCounts[char]++
|
||||
}
|
||||
|
||||
invLength := 1.0 / float64(len(data))
|
||||
for _, count := range charCounts {
|
||||
freq := float64(count) * invLength
|
||||
entropy -= freq * math.Log2(freq)
|
||||
}
|
||||
|
||||
return entropy
|
||||
}
|
||||
Reference in new issue
Block a user