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

refactor: fix revive.early-return issues #1087

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}