Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust reg compile code location #27

Merged
merged 2 commits into from Jun 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 8 additions & 9 deletions wrapcheck/wrapcheck.go
Expand Up @@ -74,7 +74,7 @@ type WrapcheckConfig struct {
// to a underlying interface name, will ignore unwrapped errors returned from a
// function whose call is defined on the given interface.
//
// For example, an ignoreInterfaceRegexps of `[]string{"Transac(tor|tion)"}`` will ignore errors
// For example, an ignoreInterfaceRegexps of `[]string{"Transac(tor|tion)"}` will ignore errors
// returned from any function whose call is defined on a interface named 'Transactor'
// or 'Transaction' due to the name matching the regular expression `Transac(tor|tion)`.
IgnoreInterfaceRegexps []string `mapstructure:"ignoreInterfaceRegexps" yaml:"ignoreInterfaceRegexps"`
Expand Down Expand Up @@ -112,7 +112,6 @@ func run(cfg WrapcheckConfig) func(*analysis.Pass) (interface{}, error) {
}
if err == nil {
ignorePackageGlobs, err = compileGlobs(cfg.IgnorePackageGlobs)

}

return func(pass *analysis.Pass) (interface{}, error) {
Expand Down Expand Up @@ -305,7 +304,7 @@ func isFromOtherPkg(pass *analysis.Pass, sel *ast.SelectorExpr, pkgGlobs []glob.
// `=`. This does not include `var` statements. This function will return nil if
// the only declaration is a `var` (aka ValueSpec) declaration.
func prevErrAssign(pass *analysis.Pass, file *ast.File, returnIdent *ast.Ident) *ast.AssignStmt {
// A slice containing all the assignments which contain an identifer
// A slice containing all the assignments which contain an identifier
// referring to the source declaration of the error. This is to catch
// cases where err is defined once, and then reassigned multiple times
// within the same block. In these cases, we should check the method of
Expand Down Expand Up @@ -399,14 +398,14 @@ func isUnresolved(file *ast.File, ident *ast.Ident) bool {
// compileRegexps compiles a set of regular expressions returning them for use,
// or the first encountered error due to an invalid expression.
func compileRegexps(regexps []string) ([]*regexp.Regexp, error) {
var compiledRegexps []*regexp.Regexp
for _, reg := range regexps {
compiledRegexps := make([]*regexp.Regexp, len(regexps))
for idx, reg := range regexps {
re, err := regexp.Compile(reg)
if err != nil {
return nil, fmt.Errorf("unable to compile regexp %s: %v\n", reg, err)
}

compiledRegexps = append(compiledRegexps, re)
compiledRegexps[idx] = re
}

return compiledRegexps, nil
Expand All @@ -415,14 +414,14 @@ func compileRegexps(regexps []string) ([]*regexp.Regexp, error) {
// compileGlobs compiles a set of globs, returning them for use,
// or the first encountered error due to an invalid expression.
func compileGlobs(globs []string) ([]glob.Glob, error) {
var compiledGlobs []glob.Glob
for _, globString := range globs {
compiledGlobs := make([]glob.Glob, len(globs))
for idx, globString := range globs {
glob, err := glob.Compile(globString)
if err != nil {
return nil, fmt.Errorf("unable to compile globs %s: %v\n", glob, err)
}

compiledGlobs = append(compiledGlobs, glob)
compiledGlobs[idx] = glob
}
return compiledGlobs, nil
}