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

suppress golint messages #1054

Merged
merged 1 commit into from
Feb 24, 2020
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
6 changes: 6 additions & 0 deletions codegen/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type Options struct {
GeneratedHeader bool
// PackageDoc is documentation written above the package line
PackageDoc string
// FileNotice is notice written below the package line
FileNotice string
// Data will be passed to the template execution.
Data interface{}
Funcs template.FuncMap
Expand Down Expand Up @@ -144,6 +146,10 @@ func Render(cfg Options) error {
result.WriteString("package ")
result.WriteString(cfg.PackageName)
result.WriteString("\n\n")
if cfg.FileNotice != "" {
result.WriteString(cfg.FileNotice)
result.WriteString("\n\n")
}
result.WriteString("import (\n")
result.WriteString(CurrentImports.String())
result.WriteString(")\n")
Expand Down
42 changes: 32 additions & 10 deletions codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// THIS CODE IS A STARTING POINT ONLY. IT WILL NOT BE UPDATED WITH SCHEMA CHANGES.
package testserver

// THIS CODE IS A STARTING POINT ONLY. IT WILL NOT BE UPDATED WITH SCHEMA CHANGES.

import (
"context"

Expand Down Expand Up @@ -306,17 +307,38 @@ func (r *userResolver) Friends(ctx context.Context, obj *User) ([]*User, error)
panic("not implemented")
}

// BackedByInterface returns BackedByInterfaceResolver implementation.
func (r *Resolver) BackedByInterface() BackedByInterfaceResolver { return &backedByInterfaceResolver{r} }
func (r *Resolver) Errors() ErrorsResolver { return &errorsResolver{r} }
func (r *Resolver) ForcedResolver() ForcedResolverResolver { return &forcedResolverResolver{r} }
func (r *Resolver) ModelMethods() ModelMethodsResolver { return &modelMethodsResolver{r} }

// Errors returns ErrorsResolver implementation.
func (r *Resolver) Errors() ErrorsResolver { return &errorsResolver{r} }

// ForcedResolver returns ForcedResolverResolver implementation.
func (r *Resolver) ForcedResolver() ForcedResolverResolver { return &forcedResolverResolver{r} }

// ModelMethods returns ModelMethodsResolver implementation.
func (r *Resolver) ModelMethods() ModelMethodsResolver { return &modelMethodsResolver{r} }

// OverlappingFields returns OverlappingFieldsResolver implementation.
func (r *Resolver) OverlappingFields() OverlappingFieldsResolver { return &overlappingFieldsResolver{r} }
func (r *Resolver) Panics() PanicsResolver { return &panicsResolver{r} }
func (r *Resolver) Primitive() PrimitiveResolver { return &primitiveResolver{r} }
func (r *Resolver) PrimitiveString() PrimitiveStringResolver { return &primitiveStringResolver{r} }
func (r *Resolver) Query() QueryResolver { return &queryResolver{r} }
func (r *Resolver) Subscription() SubscriptionResolver { return &subscriptionResolver{r} }
func (r *Resolver) User() UserResolver { return &userResolver{r} }

// Panics returns PanicsResolver implementation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤢

If you can build them out of a template then its not giving any context or new information to the reader. This is just pure noise.

can we tell golint to ignore these semi-generated files instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, We can't... 😿 I agreed about its noisy comment. but I need suppress golint error messages...
golint can't configure that same as gofmt.
golint only have -min_confidence options.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I highly recommend https://github.com/golangci/golangci-lint.

It will speed up your builds, provide consistent formatting and give you the ability to skip linters consistently on a line/function/file basis based on consistent comments - https://github.com/golangci/golangci-lint#false-positives

Copy link
Collaborator Author

@vvakame vvakame Feb 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I know... but Our project can't it immediately.
and, I don't think gqlgen should not limit what tools users should use.
this change is little bit noisy, but useful for golint user I think.

func (r *Resolver) Panics() PanicsResolver { return &panicsResolver{r} }

// Primitive returns PrimitiveResolver implementation.
func (r *Resolver) Primitive() PrimitiveResolver { return &primitiveResolver{r} }

// PrimitiveString returns PrimitiveStringResolver implementation.
func (r *Resolver) PrimitiveString() PrimitiveStringResolver { return &primitiveStringResolver{r} }

// Query returns QueryResolver implementation.
func (r *Resolver) Query() QueryResolver { return &queryResolver{r} }

// Subscription returns SubscriptionResolver implementation.
func (r *Resolver) Subscription() SubscriptionResolver { return &subscriptionResolver{r} }

// User returns UserResolver implementation.
func (r *Resolver) User() UserResolver { return &userResolver{r} }

type backedByInterfaceResolver struct{ *Resolver }
type errorsResolver struct{ *Resolver }
Expand Down
8 changes: 6 additions & 2 deletions example/config/schema.resolvers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
package config

import (
"context"
Expand All @@ -24,8 +25,11 @@ func (r *queryResolver) Todos(ctx context.Context) ([]*Todo, error) {
return r.todos, nil
}

// Mutation returns MutationResolver implementation.
func (r *Resolver) Mutation() MutationResolver { return &mutationResolver{r} }
func (r *Resolver) Query() QueryResolver { return &queryResolver{r} }

// Query returns QueryResolver implementation.
func (r *Resolver) Query() QueryResolver { return &queryResolver{r} }

type mutationResolver struct{ *Resolver }
type queryResolver struct{ *Resolver }
4 changes: 3 additions & 1 deletion example/config/todo.resolvers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
package config

import (
"context"
Expand All @@ -17,6 +18,7 @@ func (r *todoResolver) ID(ctx context.Context, obj *Todo) (string, error) {
return obj.ID, nil
}

// Todo returns TodoResolver implementation.
func (r *Resolver) Todo() TodoResolver { return &todoResolver{r} }

type todoResolver struct{ *Resolver }
4 changes: 3 additions & 1 deletion example/federation/accounts/graph/entity.resolvers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graph

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
package graph

import (
"context"
Expand All @@ -21,6 +22,7 @@ func (r *entityResolver) FindUserByID(ctx context.Context, id string) (*model.Us
}, nil
}

// Entity returns generated.EntityResolver implementation.
func (r *Resolver) Entity() generated.EntityResolver { return &entityResolver{r} }

type entityResolver struct{ *Resolver }
4 changes: 3 additions & 1 deletion example/federation/accounts/graph/schema.resolvers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graph

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
package graph

import (
"context"
Expand All @@ -16,6 +17,7 @@ func (r *queryResolver) Me(ctx context.Context) (*model.User, error) {
}, nil
}

// Query returns generated.QueryResolver implementation.
func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }

type queryResolver struct{ *Resolver }
4 changes: 3 additions & 1 deletion example/federation/products/graph/entity.resolvers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graph

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
package graph

import (
"context"
Expand All @@ -18,6 +19,7 @@ func (r *entityResolver) FindProductByUpc(ctx context.Context, upc string) (*mod
return nil, nil
}

// Entity returns generated.EntityResolver implementation.
func (r *Resolver) Entity() generated.EntityResolver { return &entityResolver{r} }

type entityResolver struct{ *Resolver }
4 changes: 3 additions & 1 deletion example/federation/products/graph/schema.resolvers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graph

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
package graph

import (
"context"
Expand All @@ -13,6 +14,7 @@ func (r *queryResolver) TopProducts(ctx context.Context, first *int) ([]*model.P
return hats, nil
}

// Query returns generated.QueryResolver implementation.
func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }

type queryResolver struct{ *Resolver }
4 changes: 3 additions & 1 deletion example/federation/reviews/graph/entity.resolvers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graph

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
package graph

import (
"context"
Expand All @@ -21,6 +22,7 @@ func (r *entityResolver) FindUserByID(ctx context.Context, id string) (*model.Us
}, nil
}

// Entity returns generated.EntityResolver implementation.
func (r *Resolver) Entity() generated.EntityResolver { return &entityResolver{r} }

type entityResolver struct{ *Resolver }
8 changes: 6 additions & 2 deletions example/federation/reviews/graph/schema.resolvers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graph

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
package graph

import (
"context"
Expand Down Expand Up @@ -33,8 +34,11 @@ func (r *userResolver) Reviews(ctx context.Context, obj *model.User) ([]*model.R
return res, nil
}

// Product returns generated.ProductResolver implementation.
func (r *Resolver) Product() generated.ProductResolver { return &productResolver{r} }
func (r *Resolver) User() generated.UserResolver { return &userResolver{r} }

// User returns generated.UserResolver implementation.
func (r *Resolver) User() generated.UserResolver { return &userResolver{r} }

type productResolver struct{ *Resolver }
type userResolver struct{ *Resolver }
6 changes: 3 additions & 3 deletions plugin/resolvergen/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (m *Plugin) generateSingleFile(data *codegen.Data) error {

return templates.Render(templates.Options{
PackageName: data.Config.Resolver.Package,
PackageDoc: `// THIS CODE IS A STARTING POINT ONLY. IT WILL NOT BE UPDATED WITH SCHEMA CHANGES.`,
FileNotice: `// THIS CODE IS A STARTING POINT ONLY. IT WILL NOT BE UPDATED WITH SCHEMA CHANGES.`,
Filename: data.Config.Resolver.Filename,
Data: resolverBuild,
Packages: data.Config.Packages,
Expand Down Expand Up @@ -132,7 +132,7 @@ func (m *Plugin) generatePerSchema(data *codegen.Data) error {

err := templates.Render(templates.Options{
PackageName: data.Config.Resolver.Package,
PackageDoc: `
FileNotice: `
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.`,
Filename: filename,
Expand All @@ -147,7 +147,7 @@ func (m *Plugin) generatePerSchema(data *codegen.Data) error {
if _, err := os.Stat(data.Config.Resolver.Filename); os.IsNotExist(errors.Cause(err)) {
err := templates.Render(templates.Options{
PackageName: data.Config.Resolver.Package,
PackageDoc: `
FileNotice: `
// This file will not be regenerated automatically.
//
// It serves as dependency injection for your app, add any dependencies you require here.`,
Expand Down
1 change: 1 addition & 0 deletions plugin/resolvergen/resolver.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
{{ end }}

{{ range $object := .Objects -}}
// {{$object.Name}} returns {{ $object.ResolverInterface | ref }} implementation.
func (r *{{$.ResolverType}}) {{$object.Name}}() {{ $object.ResolverInterface | ref }} { return &{{lcFirst $object.Name}}{{ucFirst $.ResolverType}}{r} }
{{ end }}

Expand Down