Skip to content

Commit 5a4e6a3

Browse files
authored
fix golangci lint errors in the codebase (#478)
Added a base golangci-config to the codebase to get started. Some more changes are pending, and those checks are commented out in the config.
1 parent 5b025f5 commit 5a4e6a3

File tree

11 files changed

+89
-56
lines changed

11 files changed

+89
-56
lines changed

.golangci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
run:
2+
timeout: 5m
3+
4+
linters-settings:
5+
gofmt:
6+
simplify: true
7+
govet:
8+
check-shadowing: true
9+
enable-all: true
10+
disable:
11+
- fieldalignment
12+
- composites # remove later
13+
- deepequalerrors # remove later
14+
15+
linters:
16+
disable-all: true
17+
enable:
18+
- deadcode
19+
- gofmt
20+
- gosimple
21+
- govet
22+
- ineffassign
23+
- exportloopref
24+
- structcheck
25+
- staticcheck
26+
- unconvert
27+
- unused
28+
- varcheck
29+
# - misspell add later
30+
- goimports
31+
32+
issues:
33+
exclude-rules:
34+
- linters:
35+
- unused
36+
path: "graphql_test.go"

example/scalar_map/server.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@ import (
1010
"github.com/graph-gophers/graphql-go/relay"
1111
)
1212

13-
1413
type Args struct {
1514
Name string
1615
Data types.Map
1716
}
1817

19-
2018
type mutation struct{}
2119

22-
func (_ *mutation) Hello(args Args) string {
20+
func (_ *mutation) Hello(args Args) string {
2321

2422
fmt.Println(args)
25-
23+
2624
return "Args accept!"
2725
}
2826

example/scalar_map/types/map.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package types
22

33
import "fmt"
44

5-
type Map map[string]interface {}
5+
type Map map[string]interface{}
66

77
func (Map) ImplementsGraphQLType(name string) bool {
8-
return name == "Map"
8+
return name == "Map"
99
}
1010

1111
func (j *Map) UnmarshalGraphQL(input interface{}) error {

graphql.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func Tracer(tracer trace.Tracer) SchemaOpt {
132132

133133
// ValidationTracer is used to trace validation errors. It defaults to trace.NoopValidationTracer.
134134
// Deprecated: context is needed to support tracing correctly. Use a Tracer which implements trace.ValidationTracerContext.
135-
func ValidationTracer(tracer trace.ValidationTracer) SchemaOpt {
135+
func ValidationTracer(tracer trace.ValidationTracer) SchemaOpt { //nolint:staticcheck
136136
return func(s *Schema) {
137137
s.validationTracer = &validationBridgingTracer{tracer: tracer}
138138
}
@@ -297,7 +297,7 @@ func (s *Schema) validateSchema() error {
297297
}
298298

299299
type validationBridgingTracer struct {
300-
tracer trace.ValidationTracer
300+
tracer trace.ValidationTracer //nolint:staticcheck
301301
}
302302

303303
func (t *validationBridgingTracer) TraceValidation(context.Context) trace.TraceValidationFinishFunc {

graphql_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ func TestNilInterface(t *testing.T) {
715715
}
716716
`,
717717
ExpectedErrors: []*gqlerrors.QueryError{
718-
&gqlerrors.QueryError{
718+
{
719719
Message: "x",
720720
Path: []interface{}{"b"},
721721
ResolverError: errors.New("x"),
@@ -753,7 +753,7 @@ func TestErrorPropagationInLists(t *testing.T) {
753753
null
754754
`,
755755
ExpectedErrors: []*gqlerrors.QueryError{
756-
&gqlerrors.QueryError{
756+
{
757757
Message: droidNotFoundError.Error(),
758758
Path: []interface{}{"findDroids", 1, "name"},
759759
ResolverError: droidNotFoundError,
@@ -795,7 +795,7 @@ func TestErrorPropagationInLists(t *testing.T) {
795795
}
796796
`,
797797
ExpectedErrors: []*gqlerrors.QueryError{
798-
&gqlerrors.QueryError{
798+
{
799799
Message: droidNotFoundError.Error(),
800800
Path: []interface{}{"findDroids", 1, "name"},
801801
ResolverError: droidNotFoundError,
@@ -829,7 +829,7 @@ func TestErrorPropagationInLists(t *testing.T) {
829829
}
830830
`,
831831
ExpectedErrors: []*gqlerrors.QueryError{
832-
&gqlerrors.QueryError{
832+
{
833833
Message: `graphql: got nil for non-null "Droid"`,
834834
Path: []interface{}{"findNilDroids", 1},
835835
},
@@ -906,7 +906,7 @@ func TestErrorPropagationInLists(t *testing.T) {
906906
}
907907
`,
908908
ExpectedErrors: []*gqlerrors.QueryError{
909-
&gqlerrors.QueryError{
909+
{
910910
Message: quoteError.Error(),
911911
ResolverError: quoteError,
912912
Path: []interface{}{"findDroids", 0, "quotes"},
@@ -941,12 +941,12 @@ func TestErrorPropagationInLists(t *testing.T) {
941941
}
942942
`,
943943
ExpectedErrors: []*gqlerrors.QueryError{
944-
&gqlerrors.QueryError{
944+
{
945945
Message: quoteError.Error(),
946946
ResolverError: quoteError,
947947
Path: []interface{}{"findNilDroids", 0, "quotes"},
948948
},
949-
&gqlerrors.QueryError{
949+
{
950950
Message: `graphql: got nil for non-null "Droid"`,
951951
Path: []interface{}{"findNilDroids", 1},
952952
},
@@ -985,7 +985,7 @@ func TestErrorWithExtensions(t *testing.T) {
985985
null
986986
`,
987987
ExpectedErrors: []*gqlerrors.QueryError{
988-
&gqlerrors.QueryError{
988+
{
989989
Message: droidNotFoundError.Error(),
990990
Path: []interface{}{"FindDroid"},
991991
ResolverError: droidNotFoundError,
@@ -1021,7 +1021,7 @@ func TestErrorWithNoExtensions(t *testing.T) {
10211021
null
10221022
`,
10231023
ExpectedErrors: []*gqlerrors.QueryError{
1024-
&gqlerrors.QueryError{
1024+
{
10251025
Message: err.Error(),
10261026
Path: []interface{}{"DismissVader"},
10271027
ResolverError: err,

internal/common/lexer_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,21 @@ func TestConsume(t *testing.T) {
9494
}
9595
}
9696

97-
var multilineStringTests = []consumeTestCase {
97+
var multilineStringTests = []consumeTestCase{
9898
{
99-
description: "Oneline strings are okay",
100-
definition: `"Hello World"`,
101-
expected: "",
102-
failureExpected: false,
103-
useStringDescriptions: true,
99+
description: "Oneline strings are okay",
100+
definition: `"Hello World"`,
101+
expected: "",
102+
failureExpected: false,
103+
useStringDescriptions: true,
104104
},
105105
{
106106
description: "Multiline strings are not allowed",
107107
definition: `"Hello
108108
World"`,
109-
expected: `graphql: syntax error: literal not terminated (line 1, column 1)`,
110-
failureExpected: true,
111-
useStringDescriptions: true,
109+
expected: `graphql: syntax error: literal not terminated (line 1, column 1)`,
110+
failureExpected: true,
111+
useStringDescriptions: true,
112112
},
113113
}
114114

@@ -130,5 +130,5 @@ func TestMultilineString(t *testing.T) {
130130
t.Fatalf("Test '%s' failed with error: '%s'", test.description, err.Error())
131131
}
132132
})
133-
}
133+
}
134134
}

internal/exec/resolvable/meta.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package resolvable
22

33
import (
4-
"fmt"
54
"reflect"
65

76
"github.com/graph-gophers/graphql-go/introspection"
@@ -42,23 +41,23 @@ func newMeta(s *types.Schema) *Meta {
4241
Name: "__typename",
4342
Type: &types.NonNull{OfType: s.Types["String"]},
4443
},
45-
TraceLabel: fmt.Sprintf("GraphQL field: __typename"),
44+
TraceLabel: "GraphQL field: __typename",
4645
}
4746

4847
fieldSchema := Field{
4948
FieldDefinition: types.FieldDefinition{
5049
Name: "__schema",
5150
Type: s.Types["__Schema"],
5251
},
53-
TraceLabel: fmt.Sprintf("GraphQL field: __schema"),
52+
TraceLabel: "GraphQL field: __schema",
5453
}
5554

5655
fieldType := Field{
5756
FieldDefinition: types.FieldDefinition{
5857
Name: "__type",
5958
Type: s.Types["__Type"],
6059
},
61-
TraceLabel: fmt.Sprintf("GraphQL field: __type"),
60+
TraceLabel: "GraphQL field: __type",
6261
}
6362

6463
return &Meta{

internal/exec/selected/selected.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ func applyFragment(r *Request, s *resolvable.Schema, e *resolvable.Object, frag
176176
t := r.Schema.Resolve(frag.On.Name)
177177
face, ok := t.(*types.InterfaceTypeDefinition)
178178
if !ok && frag.On.Name != "" {
179-
a, ok := e.TypeAssertions[frag.On.Name]
180-
if !ok {
179+
a, ok2 := e.TypeAssertions[frag.On.Name]
180+
if !ok2 {
181181
panic(fmt.Errorf("%q does not implement %q", frag.On, e.Name)) // TODO proper error handling
182182
}
183183

internal/query/query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111

1212
const (
1313
Query types.OperationType = "QUERY"
14-
Mutation = "MUTATION"
15-
Subscription = "SUBSCRIPTION"
14+
Mutation types.OperationType = "MUTATION"
15+
Subscription types.OperationType = "SUBSCRIPTION"
1616
)
1717

1818
func Parse(queryString string) (*types.ExecutableDefinition, *errors.QueryError) {

internal/schema/schema_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,9 @@ Second line of the description.
469469
return fmt.Errorf("Expected 3 possible types, but instead got %d types", len(typ.UnionMemberTypes))
470470
}
471471
posible := map[string]struct{}{
472-
"Coloured": struct{}{},
473-
"Named": struct{}{},
474-
"Numbered": struct{}{},
472+
"Coloured": {},
473+
"Named": {},
474+
"Numbered": {},
475475
}
476476
for _, pt := range typ.UnionMemberTypes {
477477
if _, ok := posible[pt.Name]; !ok {
@@ -503,11 +503,11 @@ Second line of the description.
503503
return fmt.Errorf("Expected 5 enum values, but instead got %d types", len(typ.EnumValuesDefinition))
504504
}
505505
posible := map[string]struct{}{
506-
"AUD": struct{}{},
507-
"USD": struct{}{},
508-
"EUR": struct{}{},
509-
"BGN": struct{}{},
510-
"GBP": struct{}{},
506+
"AUD": {},
507+
"USD": {},
508+
"EUR": {},
509+
"BGN": {},
510+
"GBP": {},
511511
}
512512
for _, v := range typ.EnumValuesDefinition {
513513
if _, ok := posible[v.EnumValue]; !ok {
@@ -604,9 +604,9 @@ Second line of the description.
604604
return fmt.Errorf("Expected 3 possible types, but instead got %d types", len(typ.UnionMemberTypes))
605605
}
606606
posible := map[string]struct{}{
607-
"Coloured": struct{}{},
608-
"Named": struct{}{},
609-
"Numbered": struct{}{},
607+
"Coloured": {},
608+
"Named": {},
609+
"Numbered": {},
610610
}
611611
for _, pt := range typ.UnionMemberTypes {
612612
if _, ok := posible[pt.Name]; !ok {
@@ -641,10 +641,10 @@ Second line of the description.
641641
return fmt.Errorf("Expected 4 fields, but instead got %d types", len(typ.Values))
642642
}
643643
posible := map[string]struct{}{
644-
"id": struct{}{},
645-
"name": struct{}{},
646-
"category": struct{}{},
647-
"tags": struct{}{},
644+
"id": {},
645+
"name": {},
646+
"category": {},
647+
"tags": {},
648648
}
649649
for _, pt := range typ.Values {
650650
if _, ok := posible[pt.Name.Name]; !ok {
@@ -741,9 +741,9 @@ Second line of the description.
741741
return fmt.Errorf("Expected 3 fields, but instead got %d types", len(typ.Fields))
742742
}
743743
fields := map[string]struct{}{
744-
"id": struct{}{},
745-
"name": struct{}{},
746-
"category": struct{}{},
744+
"id": {},
745+
"name": {},
746+
"category": {},
747747
}
748748
for _, f := range typ.Fields {
749749
if _, ok := fields[f.Name]; !ok {
@@ -861,8 +861,8 @@ Second line of the description.
861861
if test.validateError == nil {
862862
t.Fatal(err)
863863
}
864-
if err := test.validateError(err); err != nil {
865-
t.Fatal(err)
864+
if err2 := test.validateError(err); err2 != nil {
865+
t.Fatal(err2)
866866
}
867867
}
868868
if test.validateSchema != nil {

0 commit comments

Comments
 (0)