From 2591ea36be96a057f27c571668f303ce95647f8b Mon Sep 17 00:00:00 2001 From: andrey1s Date: Wed, 24 Jul 2019 11:12:40 +0300 Subject: [PATCH] fix lint prealloc --- .golangci.yml | 1 - codegen/config/config.go | 8 ++++---- codegen/field.go | 8 ++++---- graphql/introspection/schema.go | 18 +++++++++--------- handler/websocket.go | 6 +++--- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 1378545def..da6c0db6bb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,7 +19,6 @@ linters: - gochecknoinits - gocyclo - scopelint - - prealloc - goconst - maligned - golint diff --git a/codegen/config/config.go b/codegen/config/config.go index db9db01d36..8e8992e37c 100644 --- a/codegen/config/config.go +++ b/codegen/config/config.go @@ -16,7 +16,7 @@ import ( "github.com/pkg/errors" "github.com/vektah/gqlparser" "github.com/vektah/gqlparser/ast" - yaml "gopkg.in/yaml.v2" + "gopkg.in/yaml.v2" ) type Config struct { @@ -459,9 +459,9 @@ func (c *Config) InjectBuiltins(s *ast.Schema) { func (c *Config) LoadSchema() (*ast.Schema, map[string]string, error) { schemaStrings := map[string]string{} - var sources []*ast.Source + sources := make([]*ast.Source, len(c.SchemaFilename)) - for _, filename := range c.SchemaFilename { + for i, filename := range c.SchemaFilename { filename = filepath.ToSlash(filename) var err error var schemaRaw []byte @@ -471,7 +471,7 @@ func (c *Config) LoadSchema() (*ast.Schema, map[string]string, error) { os.Exit(1) } schemaStrings[filename] = string(schemaRaw) - sources = append(sources, &ast.Source{Name: filename, Input: schemaStrings[filename]}) + sources[i] = &ast.Source{Name: filename, Input: schemaStrings[filename]} } schema, err := gqlparser.LoadSchema(sources...) diff --git a/codegen/field.go b/codegen/field.go index 2cd8417d81..fab26f2b9a 100644 --- a/codegen/field.go +++ b/codegen/field.go @@ -384,16 +384,16 @@ func (f *Field) ComplexitySignature() string { } func (f *Field) ComplexityArgs() string { - var args []string - for _, arg := range f.Args { - args = append(args, "args["+strconv.Quote(arg.Name)+"].("+templates.CurrentImports.LookupType(arg.TypeReference.GO)+")") + args := make([]string, len(f.Args)) + for i, arg := range f.Args { + args[i] = "args[" + strconv.Quote(arg.Name) + "].(" + templates.CurrentImports.LookupType(arg.TypeReference.GO) + ")" } return strings.Join(args, ", ") } func (f *Field) CallArgs() string { - var args []string + args := make([]string, 0, len(f.Args)+2) if f.IsResolver { args = append(args, "rctx") diff --git a/graphql/introspection/schema.go b/graphql/introspection/schema.go index b5d2c48224..a57272d525 100644 --- a/graphql/introspection/schema.go +++ b/graphql/introspection/schema.go @@ -11,7 +11,7 @@ type Schema struct { } func (s *Schema) Types() []Type { - var types []Type + types := make([]Type, 0, len(s.schema.Types)) for _, typ := range s.schema.Types { if strings.HasPrefix(typ.Name, "__") { continue @@ -34,7 +34,7 @@ func (s *Schema) SubscriptionType() *Type { } func (s *Schema) Directives() []Directive { - var res []Directive + res := make([]Directive, 0, len(s.schema.Directives)) for _, d := range s.schema.Directives { res = append(res, s.directiveFromDef(d)) @@ -44,19 +44,19 @@ func (s *Schema) Directives() []Directive { } func (s *Schema) directiveFromDef(d *ast.DirectiveDefinition) Directive { - var locs []string - for _, loc := range d.Locations { - locs = append(locs, string(loc)) + locs := make([]string, len(d.Locations)) + for i, loc := range d.Locations { + locs[i] = string(loc) } - var args []InputValue - for _, arg := range d.Arguments { - args = append(args, InputValue{ + args := make([]InputValue, len(d.Arguments)) + for i, arg := range d.Arguments { + args[i] = InputValue{ Name: arg.Name, Description: arg.Description, DefaultValue: defaultValue(arg.DefaultValue), Type: WrapTypeFromType(s.schema, arg.Type), - }) + } } return Directive{ diff --git a/handler/websocket.go b/handler/websocket.go index 07a1a8c2dd..b31c5db18f 100644 --- a/handler/websocket.go +++ b/handler/websocket.go @@ -279,9 +279,9 @@ func (c *wsConnection) sendData(id string, response *graphql.Response) { } func (c *wsConnection) sendError(id string, errors ...*gqlerror.Error) { - var errs []error - for _, err := range errors { - errs = append(errs, err) + errs := make([]error, len(errors)) + for i, err := range errors { + errs[i] = err } b, err := json.Marshal(errs) if err != nil {