Skip to content

Commit

Permalink
refactor: fix revive.early-return issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Oct 29, 2024
1 parent 14babf2 commit 3515ff2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions rule/dot-imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions rule/var-naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 3515ff2

Please sign in to comment.