-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
40 lines (32 loc) · 823 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package erreql
import (
"regexp"
"strings"
)
type Config struct {
// Skip warning on switch statements in addition to equality checks.
//
// Default: false
SkipSwitches bool
// Regexps for packages that use sentinel error values to indicate success.
// Inlined as fmt.Sprintf(`^(%s)$`, strings.Join(SkipPackages, "|"))
//
// Default: []string{"errors", "errors_test"}
SkipPackages []string
}
type config struct {
Config
packageChecker *regexp.Regexp
}
func (c Config) compileConfig() config {
if len(c.SkipPackages) == 0 {
c.SkipPackages = []string{"errors", "errors_test"}
}
return config{
Config: c,
packageChecker: regexp.MustCompile(`^(?:` + strings.Join(c.SkipPackages, "|") + `)$`),
}
}
func (c config) skipPackage(pkg string) bool {
return c.packageChecker.MatchString(pkg)
}