Skip to content

Commit 21e7fb4

Browse files
committed
simplify single case type switches
Found such switches using https://go-critic.github.io/overview#singleCaseSwitch-ref
1 parent 990c305 commit 21e7fb4

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

introspection.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,7 @@ func init() {
550550
TypeType.AddFieldConfig("interfaces", &Field{
551551
Type: NewList(NewNonNull(TypeType)),
552552
Resolve: func(p ResolveParams) (interface{}, error) {
553-
switch ttype := p.Source.(type) {
554-
case *Object:
553+
if ttype, ok := p.Source.(*Object); ok {
555554
return ttype.Interfaces(), nil
556555
}
557556
return nil, nil
@@ -579,8 +578,7 @@ func init() {
579578
},
580579
Resolve: func(p ResolveParams) (interface{}, error) {
581580
includeDeprecated, _ := p.Args["includeDeprecated"].(bool)
582-
switch ttype := p.Source.(type) {
583-
case *Enum:
581+
if ttype, ok := p.Source.(*Enum); ok {
584582
if includeDeprecated {
585583
return ttype.Values(), nil
586584
}
@@ -599,8 +597,7 @@ func init() {
599597
TypeType.AddFieldConfig("inputFields", &Field{
600598
Type: NewList(NewNonNull(InputValueType)),
601599
Resolve: func(p ResolveParams) (interface{}, error) {
602-
switch ttype := p.Source.(type) {
603-
case *InputObject:
600+
if ttype, ok := p.Source.(*InputObject); ok {
604601
fields := []*InputObjectField{}
605602
for _, field := range ttype.Fields() {
606603
fields = append(fields, field)

language/visitor/visitor.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -609,19 +609,20 @@ func VisitInParallel(visitorOptsSlice ...*VisitorOptions) *VisitorOptions {
609609
Enter: func(p VisitFuncParams) (string, interface{}) {
610610
for i, visitorOpts := range visitorOptsSlice {
611611
if _, ok := skipping[i]; !ok {
612-
switch node := p.Node.(type) {
613-
case ast.Node:
614-
kind := node.GetKind()
615-
fn := GetVisitFn(visitorOpts, kind, false)
616-
if fn != nil {
617-
action, result := fn(p)
618-
if action == ActionSkip {
619-
skipping[i] = node
620-
} else if action == ActionBreak {
621-
skipping[i] = ActionBreak
622-
} else if action == ActionUpdate {
623-
return ActionUpdate, result
624-
}
612+
node, ok := p.Node.(ast.Node)
613+
if !ok {
614+
continue
615+
}
616+
kind := node.GetKind()
617+
fn := GetVisitFn(visitorOpts, kind, false)
618+
if fn != nil {
619+
action, result := fn(p)
620+
if action == ActionSkip {
621+
skipping[i] = node
622+
} else if action == ActionBreak {
623+
skipping[i] = ActionBreak
624+
} else if action == ActionUpdate {
625+
return ActionUpdate, result
625626
}
626627
}
627628
}
@@ -632,8 +633,7 @@ func VisitInParallel(visitorOptsSlice ...*VisitorOptions) *VisitorOptions {
632633
for i, visitorOpts := range visitorOptsSlice {
633634
skippedNode, ok := skipping[i]
634635
if !ok {
635-
switch node := p.Node.(type) {
636-
case ast.Node:
636+
if node, ok := p.Node.(ast.Node); ok {
637637
kind := node.GetKind()
638638
fn := GetVisitFn(visitorOpts, kind, true)
639639
if fn != nil {

0 commit comments

Comments
 (0)