Skip to content

Commit

Permalink
fix lint prealloc
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey1s committed Jul 24, 2019
1 parent 3b0e44f commit 2591ea3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ linters:
- gochecknoinits
- gocyclo
- scopelint
- prealloc
- goconst
- maligned
- golint
Expand Down
8 changes: 4 additions & 4 deletions codegen/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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...)
Expand Down
8 changes: 4 additions & 4 deletions codegen/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 9 additions & 9 deletions graphql/introspection/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions handler/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2591ea3

Please sign in to comment.