1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-21 17:16:40 +02:00

refactor: fix revive.early-return issues (#1087)

This commit is contained in:
Oleksandr Redko 2024-10-29 13:48:49 +02:00 committed by GitHub
parent 14babf2824
commit 0ac1ef7298
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 14 deletions

View File

@ -59,17 +59,17 @@ func (r *DotImportsRule) configure(arguments lint.Arguments) {
}
if allowedPkgArg, ok := args["allowedPackages"]; ok {
if pkgs, ok := allowedPkgArg.([]any); ok {
for _, p := range pkgs {
if pkg, ok := p.(string); ok {
r.allowedPackages.add(pkg)
} else {
panic(fmt.Sprintf("Invalid argument to the dot-imports rule, string expected. Got '%v' (%T)", p, p))
}
}
} else {
pkgs, ok := allowedPkgArg.([]any)
if !ok {
panic(fmt.Sprintf("Invalid argument to the dot-imports rule, []string expected. Got '%v' (%T)", allowedPkgArg, allowedPkgArg))
}
for _, p := range pkgs {
pkg, ok := p.(string)
if !ok {
panic(fmt.Sprintf("Invalid argument to the dot-imports rule, string expected. Got '%v' (%T)", p, p))
}
r.allowedPackages.add(pkg)
}
}
}

View File

@ -264,17 +264,17 @@ func (w *lintNames) Visit(n ast.Node) ast.Visitor {
}
func getList(arg any, argName string) []string {
temp, ok := arg.([]any)
args, ok := arg.([]any)
if !ok {
panic(fmt.Sprintf("Invalid argument to the var-naming rule. Expecting a %s of type slice with initialisms, got %T", argName, arg))
}
var list []string
for _, v := range temp {
if val, ok := v.(string); ok {
list = append(list, val)
} else {
for _, v := range args {
val, ok := v.(string)
if !ok {
panic(fmt.Sprintf("Invalid %s values of the var-naming rule. Expecting slice of strings but got element of type %T", val, arg))
}
list = append(list, val)
}
return list
}