Skip to content

Commit

Permalink
Fix prealloc linter suggestions.
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Conrad <[email protected]>
  • Loading branch information
philipaconrad committed Sep 14, 2022
1 parent 7007f8c commit ed0b70c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion validator/imported_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestValidation(t *testing.T) {
d.pattern = regexp.MustCompile("^" + d.Rule + "$")
}

var schemas []*ast.Schema
var schemas = make([]*ast.Schema, 0, len(rawSchemas))
for i, schema := range rawSchemas {
schema, err := gqlparser.LoadSchema(&ast.Source{Input: schema, Name: fmt.Sprintf("schemas.yml[%d]", i)})
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions validator/rules/fields_on_correct_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ func getSuggestedTypeNames(walker *Walker, parent *ast.Definition, name string)
return nil
}

var suggestedObjectTypes []string
possibleTypes := walker.Schema.GetPossibleTypes(parent)
var suggestedObjectTypes = make([]string, 0, len(possibleTypes))
var suggestedInterfaceTypes []string
interfaceUsageCount := map[string]int{}

for _, possibleType := range walker.Schema.GetPossibleTypes(parent) {
for _, possibleType := range possibleTypes {
field := possibleType.Fields.ForName(name)
if field == nil {
continue
Expand Down Expand Up @@ -87,9 +88,9 @@ func getSuggestedFieldNames(parent *ast.Definition, name string) []string {
return nil
}

var possibleFieldNames []string
var possibleFieldNames = make([]string, 0, len(parent.Fields))
for _, field := range parent.Fields {
possibleFieldNames = append(possibleFieldNames, field.Name)
possibleFieldNames= append(possibleFieldNames, field.Name)
}

return SuggestionList(name, possibleFieldNames)
Expand Down

0 comments on commit ed0b70c

Please sign in to comment.