From 91966ef485331c61177b384bfb029e51eb0a3cb1 Mon Sep 17 00:00:00 2001 From: andrey1s Date: Wed, 7 Aug 2019 10:15:05 +0300 Subject: [PATCH] add example to lint --- .golangci.yml | 4 ---- example/dataloader/dataloaders.go | 1 + example/dataloader/resolvers.go | 2 ++ example/selection/selection.go | 8 +++---- example/starwars/resolvers.go | 8 +++---- .../type-system-extension/server/server.go | 22 +++++++++---------- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index da6c0db6bb6..348d4eb2c1b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,10 +2,6 @@ run: tests: true skip-dirs: - bin - - vendor - - var - - tmp - - example/* linters-settings: errcheck: diff --git a/example/dataloader/dataloaders.go b/example/dataloader/dataloaders.go index dcbb2e689f3..6978db4a9e5 100644 --- a/example/dataloader/dataloaders.go +++ b/example/dataloader/dataloaders.go @@ -24,6 +24,7 @@ type loaders struct { itemsByOrder *ItemSliceLoader } +// nolint: gosec func LoaderMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ldrs := loaders{} diff --git a/example/dataloader/resolvers.go b/example/dataloader/resolvers.go index 5e71026a7ee..ee276a39bda 100644 --- a/example/dataloader/resolvers.go +++ b/example/dataloader/resolvers.go @@ -65,6 +65,7 @@ func (r *queryResolver) Customers(ctx context.Context) ([]*Customer, error) { } // this method is here to test code generation of nested arrays +// nolint: gosec func (r *queryResolver) Torture1d(ctx context.Context, customerIds []int) ([]*Customer, error) { result := make([]*Customer, len(customerIds)) for i, id := range customerIds { @@ -74,6 +75,7 @@ func (r *queryResolver) Torture1d(ctx context.Context, customerIds []int) ([]*Cu } // this method is here to test code generation of nested arrays +// nolint: gosec func (r *queryResolver) Torture2d(ctx context.Context, customerIds [][]int) ([][]*Customer, error) { result := make([][]*Customer, len(customerIds)) for i := range customerIds { diff --git a/example/selection/selection.go b/example/selection/selection.go index e423a8a7e16..c74f13c9de0 100644 --- a/example/selection/selection.go +++ b/example/selection/selection.go @@ -3,7 +3,7 @@ package selection import ( - context "context" + "context" "fmt" "time" @@ -59,10 +59,10 @@ func (r *queryResolver) Events(ctx context.Context) ([]Event, error) { } func formatCollected(cf []graphql.CollectedField) []string { - var res []string + res := make([]string, len(cf)) - for _, f := range cf { - res = append(res, fmt.Sprintf("%s as %s", f.Name, f.Alias)) + for i, f := range cf { + res[i] = f.Name + " as " + f.Alias } return res } diff --git a/example/starwars/resolvers.go b/example/starwars/resolvers.go index e654448c756..5174bce30f5 100644 --- a/example/starwars/resolvers.go +++ b/example/starwars/resolvers.go @@ -48,13 +48,13 @@ func (r *Resolver) Starship() generated.StarshipResolver { } func (r *Resolver) resolveCharacters(ctx context.Context, ids []string) ([]models.Character, error) { - var result []models.Character - for _, id := range ids { + result := make([]models.Character, len(ids)) + for i, id := range ids { char, err := r.Query().Character(ctx, id) if err != nil { return nil, err } - result = append(result, char) + result[i] = char } return result, nil } @@ -71,7 +71,7 @@ func (r *droidResolver) FriendsConnection(ctx context.Context, obj *models.Droid type friendsConnectionResolver struct{ *Resolver } -func (r *Resolver) resolveFriendConnection(ctx context.Context, ids []string, first *int, after *string) (*models.FriendsConnection, error) { +func (r *Resolver) resolveFriendConnection(_ context.Context, ids []string, first *int, after *string) (*models.FriendsConnection, error) { from := 0 if after != nil { b, err := base64.StdEncoding.DecodeString(*after) diff --git a/example/type-system-extension/server/server.go b/example/type-system-extension/server/server.go index 19e7b292d68..d214efdfeb9 100644 --- a/example/type-system-extension/server/server.go +++ b/example/type-system-extension/server/server.go @@ -5,7 +5,7 @@ import ( "net/http" "os" - "github.com/99designs/gqlgen/example/type-system-extension" + extension "github.com/99designs/gqlgen/example/type-system-extension" "github.com/99designs/gqlgen/handler" ) @@ -19,16 +19,16 @@ func main() { http.Handle("/", handler.Playground("GraphQL playground", "/query")) http.Handle("/query", handler.GraphQL( - type_system_extension.NewExecutableSchema( - type_system_extension.Config{ - Resolvers: type_system_extension.NewRootResolver(), - Directives: type_system_extension.DirectiveRoot{ - EnumLogging: type_system_extension.EnumLogging, - FieldLogging: type_system_extension.FieldLogging, - InputLogging: type_system_extension.InputLogging, - ObjectLogging: type_system_extension.ObjectLogging, - ScalarLogging: type_system_extension.ScalarLogging, - UnionLogging: type_system_extension.UnionLogging, + extension.NewExecutableSchema( + extension.Config{ + Resolvers: extension.NewRootResolver(), + Directives: extension.DirectiveRoot{ + EnumLogging: extension.EnumLogging, + FieldLogging: extension.FieldLogging, + InputLogging: extension.InputLogging, + ObjectLogging: extension.ObjectLogging, + ScalarLogging: extension.ScalarLogging, + UnionLogging: extension.UnionLogging, }, }, ),