Skip to content
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
105 changes: 93 additions & 12 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,125 @@
# All settings can be found here https://github.com/golangci/golangci-lint/blob/HEAD/.golangci.reference.yml
version: "2"
run:
tests: true
formatters:
enable:
- golines
- gofumpt
- gci
settings:
gci:
sections:
- standard
- default
- prefix(github.com/vektah)
golines:
# Target maximum line length.
# Default: 100
max-len: 100
shorten-comments: true
exclusions:
paths:
- generated
- node_modules
- bin
- third_party$
- builtin$
- examples$
linters:
default: none
enable:
# - asasalint
# - asciicheck
# - bidichk
- bodyclose
# - copyloopvar
- dupl
# - dupword
# - durationcheck
- errcheck
- gocritic
- govet
- ineffassign
- misspell
- nakedret
- prealloc
# - nolintlint
# - perfsprint
# - reassign
- revive
- staticcheck
# - testableexamples
- testifylint
- unconvert
# - unparam
- unused
# - usestdlibvars
# - usetesting
# - wastedassign
# - prealloc # disabled because it is a huge pain
settings:
errcheck:
exclude-functions:
- (io.Writer).Write
- (http.ResponseWriter).Write
- (*bytes.Buffer).WriteByte
- (*strings.Builder).WriteByte
- (*strings.Builder).WriteString
- io.Copy
- io.WriteString
- fmt.Fprintln
gocritic:
enabled-checks:
- emptyStringTest
- equalFold
- httpNoBody
- nilValReturn
- paramTypeCombine
- preferFprint
- yodaStyleExpr
govet:
disable:
- fieldalignment
- shadow
- unusedwrite
enable-all: true
perfsprint:
int-conversion: false
err-error: false
errorf: true
sprintf1: false
strconcat: false
revive:
enable-all-rules: false
rules:
- name: empty-lines
- name: use-any
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#struct-tag
# - name: struct-tag
# exclude: ["**/*_go124_test.go"]
# - name: blank-imports
# - name: context-as-argument
# - name: context-keys-type
# - name: error-return
# - name: error-naming
# - name: exported
# disabled: true
# - name: if-return
# - name: increment-decrement
# - name: var-declaration
# - name: package-comments
# disabled: true
# - name: range
# - name: receiver-naming
# - name: time-naming
# - name: unexported-return
# - name: indent-error-flow
# - name: errorf
# - name: superfluous-else
# - name: unused-parameter
# disabled: true
# - name: unreachable-code
# - name: redefines-builtin-id
testifylint:
disable-all: true
enable:
Expand All @@ -54,14 +146,3 @@ linters:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- bin
- third_party$
- builtin$
- examples$
10 changes: 7 additions & 3 deletions ast/argmap.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package ast

func arg2map(defs ArgumentDefinitionList, args ArgumentList, vars map[string]interface{}) map[string]interface{} {
result := map[string]interface{}{}
func arg2map(
defs ArgumentDefinitionList,
args ArgumentList,
vars map[string]any,
) map[string]any {
result := map[string]any{}
var err error

for _, argDef := range defs {
var val interface{}
var val any
var hasValue bool

if argValue := args.ForName(argDef.Name); argValue != nil {
Expand Down
12 changes: 8 additions & 4 deletions ast/argmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import (

func TestArg2Map(t *testing.T) {
defs := ArgumentDefinitionList{
{Name: "A", Type: NamedType("String", nil), DefaultValue: &Value{Kind: StringValue, Raw: "defaultA"}},
{
Name: "A",
Type: NamedType("String", nil),
DefaultValue: &Value{Kind: StringValue, Raw: "defaultA"},
},
{Name: "B", Type: NamedType("String", nil)},
}

Expand Down Expand Up @@ -42,7 +46,7 @@ func TestArg2Map(t *testing.T) {
args := arg2map(defs, ArgumentList{
{Name: "A", Value: &Value{Kind: Variable, Raw: "VarA"}},
{Name: "B", Value: &Value{Kind: Variable, Raw: "VarB"}},
}, map[string]interface{}{})
}, map[string]any{})
require.Equal(t, "defaultA", args["A"])
require.NotContains(t, args, "B")
})
Expand All @@ -51,7 +55,7 @@ func TestArg2Map(t *testing.T) {
args := arg2map(defs, ArgumentList{
{Name: "A", Value: &Value{Kind: Variable, Raw: "VarA"}},
{Name: "B", Value: &Value{Kind: Variable, Raw: "VarB"}},
}, map[string]interface{}{
}, map[string]any{
"VarA": nil,
"VarB": nil,
})
Expand All @@ -65,7 +69,7 @@ func TestArg2Map(t *testing.T) {
args := arg2map(defs, ArgumentList{
{Name: "A", Value: &Value{Kind: Variable, Raw: "VarA"}},
{Name: "B", Value: &Value{Kind: Variable, Raw: "VarB"}},
}, map[string]interface{}{
}, map[string]any{
"VarA": "varvalA",
"VarB": "varvalB",
})
Expand Down
9 changes: 3 additions & 6 deletions ast/definition.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ast

import "slices"

type DefinitionKind string

const (
Expand Down Expand Up @@ -54,12 +56,7 @@ func (d *Definition) IsInputType() bool {
}

func (d *Definition) OneOf(types ...string) bool {
for _, t := range types {
if d.Name == t {
return true
}
}
return false
return slices.Contains(types, d.Name)
}

type FieldDefinition struct {
Expand Down
6 changes: 3 additions & 3 deletions ast/directive.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ast
type DirectiveLocation string

const (
// Executable
// Executable.
LocationQuery DirectiveLocation = `QUERY`
LocationMutation DirectiveLocation = `MUTATION`
LocationSubscription DirectiveLocation = `SUBSCRIPTION`
Expand All @@ -12,7 +12,7 @@ const (
LocationFragmentSpread DirectiveLocation = `FRAGMENT_SPREAD`
LocationInlineFragment DirectiveLocation = `INLINE_FRAGMENT`

// Type System
// Type System.
LocationSchema DirectiveLocation = `SCHEMA`
LocationScalar DirectiveLocation = `SCALAR`
LocationObject DirectiveLocation = `OBJECT`
Expand All @@ -38,7 +38,7 @@ type Directive struct {
Location DirectiveLocation
}

func (d *Directive) ArgumentMap(vars map[string]interface{}) map[string]interface{} {
func (d *Directive) ArgumentMap(vars map[string]any) map[string]any {
if d.Definition == nil {
return nil
}
Expand Down
7 changes: 4 additions & 3 deletions ast/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Schema struct {
Comment *CommentGroup
}

// AddTypes is the helper to add types definition to the schema
// AddTypes is the helper to add types definition to the schema.
func (s *Schema) AddTypes(defs ...*Definition) {
if s.Types == nil {
s.Types = make(map[string]*Definition)
Expand All @@ -56,7 +56,7 @@ func (s *Schema) AddPossibleType(name string, def *Definition) {
s.PossibleTypes[name] = append(s.PossibleTypes[name], def)
}

// GetPossibleTypes will enumerate all the definitions for a given interface or union
// GetPossibleTypes will enumerate all the definitions for a given interface or union.
func (s *Schema) GetPossibleTypes(def *Definition) []*Definition {
return s.PossibleTypes[def.Name]
}
Expand All @@ -65,7 +65,8 @@ func (s *Schema) AddImplements(name string, iface *Definition) {
s.Implements[name] = append(s.Implements[name], iface)
}

// GetImplements returns all the interface and union definitions that the given definition satisfies
// GetImplements returns all the interface and union definitions that the given definition
// satisfies.
func (s *Schema) GetImplements(def *Definition) []*Definition {
return s.Implements[def.Name]
}
Expand Down
74 changes: 61 additions & 13 deletions ast/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func TestQueryDocMethods(t *testing.T) {

require.NoError(t, err)
t.Run("GetOperation", func(t *testing.T) {
require.EqualValues(t, "Bob", doc.Operations.ForName("Bob").Name)
require.Equal(t, "Bob", doc.Operations.ForName("Bob").Name)
require.Nil(t, doc.Operations.ForName("Alice"))
})

t.Run("GetFragment", func(t *testing.T) {
require.EqualValues(t, "Frag", doc.Fragments.ForName("Frag").Name)
require.Equal(t, "Frag", doc.Fragments.ForName("Frag").Name)
require.Nil(t, doc.Fragments.ForName("Alice"))
})
}
Expand All @@ -34,21 +34,69 @@ func TestNamedTypeCompatability(t *testing.T) {
assert.True(t, NamedType("A", nil).IsCompatible(NamedType("A", nil)))
assert.False(t, NamedType("A", nil).IsCompatible(NamedType("B", nil)))

assert.True(t, ListType(NamedType("A", nil), nil).IsCompatible(ListType(NamedType("A", nil), nil)))
assert.False(t, ListType(NamedType("A", nil), nil).IsCompatible(ListType(NamedType("B", nil), nil)))
assert.False(t, ListType(NamedType("A", nil), nil).IsCompatible(ListType(NamedType("B", nil), nil)))
assert.True(
t,
ListType(NamedType("A", nil), nil).IsCompatible(ListType(NamedType("A", nil), nil)),
)
assert.False(
t,
ListType(NamedType("A", nil), nil).IsCompatible(ListType(NamedType("B", nil), nil)),
)
assert.False(
t,
ListType(NamedType("A", nil), nil).IsCompatible(ListType(NamedType("B", nil), nil)),
)

assert.True(t, ListType(NamedType("A", nil), nil).IsCompatible(ListType(NamedType("A", nil), nil)))
assert.False(t, ListType(NamedType("A", nil), nil).IsCompatible(ListType(NamedType("B", nil), nil)))
assert.False(t, ListType(NamedType("A", nil), nil).IsCompatible(ListType(NamedType("B", nil), nil)))
assert.True(
t,
ListType(NamedType("A", nil), nil).IsCompatible(ListType(NamedType("A", nil), nil)),
)
assert.False(
t,
ListType(NamedType("A", nil), nil).IsCompatible(ListType(NamedType("B", nil), nil)),
)
assert.False(
t,
ListType(NamedType("A", nil), nil).IsCompatible(ListType(NamedType("B", nil), nil)),
)

assert.True(t, NonNullNamedType("A", nil).IsCompatible(NamedType("A", nil)))
assert.False(t, NamedType("A", nil).IsCompatible(NonNullNamedType("A", nil)))

assert.True(t, NonNullListType(NamedType("String", nil), nil).IsCompatible(NonNullListType(NamedType("String", nil), nil)))
assert.True(t, NonNullListType(NamedType("String", nil), nil).IsCompatible(ListType(NamedType("String", nil), nil)))
assert.False(t, ListType(NamedType("String", nil), nil).IsCompatible(NonNullListType(NamedType("String", nil), nil)))
assert.True(
t,
NonNullListType(
NamedType("String", nil),
nil,
).IsCompatible(NonNullListType(NamedType("String", nil), nil)),
)
assert.True(
t,
NonNullListType(
NamedType("String", nil),
nil,
).IsCompatible(ListType(NamedType("String", nil), nil)),
)
assert.False(
t,
ListType(
NamedType("String", nil),
nil,
).IsCompatible(NonNullListType(NamedType("String", nil), nil)),
)

assert.True(t, ListType(NonNullNamedType("String", nil), nil).IsCompatible(ListType(NamedType("String", nil), nil)))
assert.False(t, ListType(NamedType("String", nil), nil).IsCompatible(ListType(NonNullNamedType("String", nil), nil)))
assert.True(
t,
ListType(
NonNullNamedType("String", nil),
nil,
).IsCompatible(ListType(NamedType("String", nil), nil)),
)
assert.False(
t,
ListType(
NamedType("String", nil),
nil,
).IsCompatible(ListType(NonNullNamedType("String", nil), nil)),
)
}
7 changes: 5 additions & 2 deletions ast/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"strings"
)

// Dump turns ast into a stable string format for assertions in tests
func Dump(i interface{}) string {
// Dump turns ast into a stable string format for assertions in tests.
func Dump(i any) string {
v := reflect.ValueOf(i)

d := dumper{Buffer: &bytes.Buffer{}}
Expand Down Expand Up @@ -146,8 +146,11 @@
return v.String() == ""
}

// TODO(steve): more correct, but breaks tests
// return reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()).Interface())

// Compare other types directly:
return reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()))

Check failure on line 153 in ast/dumper.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.24)

reflectvaluecompare: avoid using reflect.DeepEqual with reflect.Value (govet)
}

func (d *dumper) dumpPtr(v reflect.Value) {
Expand Down
Loading
Loading