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: simplify by using switch instead of if #1190

Merged
merged 1 commit into from
Dec 12, 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: 8 additions & 10 deletions rule/enforce_repeated_arg_type_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ func (r *EnforceRepeatedArgTypeStyleRule) Apply(file *lint.File, arguments lint.
ast.Inspect(astFile, func(n ast.Node) bool {
switch fn := n.(type) {
case *ast.FuncDecl:
if r.funcArgStyle == enforceRepeatedArgTypeStyleTypeFull {
switch r.funcArgStyle {
case enforceRepeatedArgTypeStyleTypeFull:
if fn.Type.Params != nil {
for _, field := range fn.Type.Params.List {
if len(field.Names) > 1 {
Expand All @@ -133,11 +134,9 @@ func (r *EnforceRepeatedArgTypeStyleRule) Apply(file *lint.File, arguments lint.
}
}
}
}

if r.funcArgStyle == enforceRepeatedArgTypeStyleTypeShort {
var prevType ast.Expr
case enforceRepeatedArgTypeStyleTypeShort:
if fn.Type.Params != nil {
var prevType ast.Expr
for _, field := range fn.Type.Params.List {
prevTypeStr := gofmt(prevType)
currentTypeStr := gofmt(field.Type)
Expand All @@ -154,7 +153,8 @@ func (r *EnforceRepeatedArgTypeStyleRule) Apply(file *lint.File, arguments lint.
}
}

if r.funcRetValStyle == enforceRepeatedArgTypeStyleTypeFull {
switch r.funcRetValStyle {
case enforceRepeatedArgTypeStyleTypeFull:
if fn.Type.Results != nil {
for _, field := range fn.Type.Results.List {
if len(field.Names) > 1 {
Expand All @@ -167,11 +167,9 @@ func (r *EnforceRepeatedArgTypeStyleRule) Apply(file *lint.File, arguments lint.
}
}
}
}

if r.funcRetValStyle == enforceRepeatedArgTypeStyleTypeShort {
var prevType ast.Expr
case enforceRepeatedArgTypeStyleTypeShort:
if fn.Type.Results != nil {
var prevType ast.Expr
for _, field := range fn.Type.Results.List {
prevTypeStr := gofmt(prevType)
currentTypeStr := gofmt(field.Type)
Expand Down
10 changes: 3 additions & 7 deletions rule/struct_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,9 @@ func (w lintStructTagRule) checkTagNameIfNeed(tag *structtag.Tag) (string, bool)
return "", true
}

needsToCheckTagName := tag.Key == keyBSON ||
tag.Key == keyJSON ||
tag.Key == keyXML ||
tag.Key == keyYAML ||
tag.Key == keyProtobuf

if !needsToCheckTagName {
switch tag.Key {
case keyBSON, keyJSON, keyXML, keyYAML, keyProtobuf:
default:
return "", true
}

Expand Down
Loading