Skip to content

Commit a11edb0

Browse files
authored
chore: fix lint errors (#185)
1 parent 5d2e076 commit a11edb0

File tree

11 files changed

+73
-64
lines changed

11 files changed

+73
-64
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Vet
2929
run: go vet ./...
3030
- name: Lint
31-
uses: golangci/golangci-lint-action@v7
31+
uses: golangci/golangci-lint-action@v8
3232
with:
3333
version: latest
3434
only-new-issues: true

.github/workflows/test.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,23 @@ jobs:
2626
docker compose up -d
2727
- name: Run Go unit tests for example/subscription
2828
run: |
29-
cd example/subscription
29+
rm -rf ./coverage
30+
mkdir -p ./coverage/subscription
31+
pushd example/subscription
3032
go get -t -v ./...
31-
go test -v -race -timeout 3m ./...
33+
popd
34+
go test -v -race -timeout 3m -cover ./... -args -test.gocoverdir=$PWD/coverage/subscription ./example/subscription/...
3235
- name: Run Go unit tests
33-
run: go test -v -race -timeout 3m -coverprofile=coverage.out ./...
36+
run: |
37+
mkdir -p ./coverage/graphql
38+
go test -v -race -timeout 3m -cover ./ ./ident/... ./pkg/... -args -test.gocoverdir=$PWD/coverage/graphql ./...
3439
- name: Go coverage format
3540
if: ${{ github.event_name == 'pull_request' && github.repository == 'hasura/go-graphql-client' }}
3641
run: |
3742
go get github.com/boumenot/gocover-cobertura
3843
go install github.com/boumenot/gocover-cobertura
39-
gocover-cobertura < coverage.out > coverage.xml
44+
go tool covdata textfmt -i=./coverage/subscription,./coverage/graphql -o ./coverage/coverage.out
45+
gocover-cobertura < ./coverage/coverage.out > coverage.xml
4046
- name: Code Coverage Summary Report
4147
if: ${{ github.event_name == 'pull_request' && github.repository == 'hasura/go-graphql-client' }}
4248
uses: irongut/[email protected]

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.idea/
2-
coverage.out
2+
coverage/
33
go.work
4-
go.work.sum
4+
go.work.sum

.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ linters:
5353
- G306
5454
- G404
5555
funlen:
56-
lines: 210
57-
statements: 120
56+
lines: 240
57+
statements: 140
5858
nestif:
5959
min-complexity: 10
6060

pkg/jsonutil/graphql.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
//
1919
// The implementation is created on top of the JSON tokenizer available
2020
// in "encoding/json".Decoder.
21-
func UnmarshalGraphQL(data []byte, v interface{}) error {
21+
func UnmarshalGraphQL(data []byte, v any) error {
2222
dec := json.NewDecoder(bytes.NewReader(data))
2323
dec.UseNumber()
2424

@@ -43,7 +43,7 @@ func UnmarshalGraphQL(data []byte, v interface{}) error {
4343
type decoder struct {
4444
tokenizer interface {
4545
Token() (json.Token, error)
46-
Decode(v interface{}) error
46+
Decode(v any) error
4747
}
4848

4949
// Stack of what part of input JSON we're in the middle of - objects, arrays.
@@ -84,7 +84,7 @@ func (s stack) TopValue() reflect.Value {
8484
}
8585

8686
// Decode decodes a single JSON value from d.tokenizer into v.
87-
func (d *decoder) Decode(v interface{}) error {
87+
func (d *decoder) Decode(v any) error {
8888
rv := reflect.ValueOf(v)
8989
if rv.Kind() != reflect.Ptr {
9090
return fmt.Errorf("cannot decode into non-pointer %T", v)
@@ -102,7 +102,7 @@ func (d *decoder) decode() error {
102102
// The loop invariant is that the top of each d.vs stack
103103
// is where we try to unmarshal the next JSON value we see.
104104
for len(d.vs) > 0 {
105-
var tok interface{}
105+
var tok any
106106
tok, err := d.tokenizer.Token()
107107

108108
if errors.Is(err, io.EOF) {
@@ -485,6 +485,7 @@ func extractUnionFieldTypeName(tag string) *string {
485485
return &typeName
486486
}
487487
}
488+
488489
return nil
489490
}
490491

@@ -498,15 +499,15 @@ func (d *decoder) filterUnionFieldsByTypeName(typeName string) {
498499
for _, st := range d.vs {
499500
if len(st) == 0 {
500501
filtered = append(filtered, st)
502+
501503
continue
502504
}
503505

504506
entry := st[len(st)-1]
505-
if entry.typeName == nil {
506-
// Not a union field (like the parent struct), keep it
507-
filtered = append(filtered, st)
508-
} else if *entry.typeName == typeName {
509-
// Union field which matches the typename, keep it
507+
508+
if entry.typeName == nil || *entry.typeName == typeName {
509+
// Not a union field (like the parent struct)
510+
// or union field which matches the typename, keep it
510511
filtered = append(filtered, st)
511512
} else {
512513
// Union field doesn't match - set it to nil if it's a pointer
@@ -609,7 +610,7 @@ func keyForGraphQLFragment(value string) bool {
609610
// unmarshalValue unmarshals JSON value into v.
610611
// v must be addressable and not obtained by the use of unexported
611612
// struct fields, otherwise unmarshalValue will panic.
612-
func unmarshalValue(value interface{}, v reflect.Value) error {
613+
func unmarshalValue(value any, v reflect.Value) error {
613614
b, err := json.Marshal(value) // TODO: Short-circuit (if profiling says it's worth it).
614615
if err != nil {
615616
return err

query.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ func constructOptions(options []Option) (*constructOptionsOutput, error) {
5858
}
5959

6060
func constructQuery(
61-
v interface{},
62-
variables map[string]interface{},
61+
v any,
62+
variables map[string]any,
6363
options ...Option,
6464
) (string, *constructOptionsOutput, error) {
6565
query, err := query(v)
@@ -96,8 +96,8 @@ func constructQuery(
9696

9797
// ConstructQuery build GraphQL query string from struct and variables.
9898
func ConstructQuery(
99-
v interface{},
100-
variables map[string]interface{},
99+
v any,
100+
variables map[string]any,
101101
options ...Option,
102102
) (string, error) {
103103
query, _, err := constructQuery(v, variables, options...)
@@ -109,8 +109,8 @@ func ConstructQuery(
109109
}
110110

111111
func constructMutation(
112-
v interface{},
113-
variables map[string]interface{},
112+
v any,
113+
variables map[string]any,
114114
options ...Option,
115115
) (string, *constructOptionsOutput, error) {
116116
query, err := query(v)
@@ -147,8 +147,8 @@ func constructMutation(
147147

148148
// ConstructMutation build GraphQL mutation string from struct and variables.
149149
func ConstructMutation(
150-
v interface{},
151-
variables map[string]interface{},
150+
v any,
151+
variables map[string]any,
152152
options ...Option,
153153
) (string, error) {
154154
query, _, err := constructMutation(v, variables, options...)
@@ -161,8 +161,8 @@ func ConstructMutation(
161161

162162
// ConstructSubscription build GraphQL subscription string from struct and variables.
163163
func ConstructSubscription(
164-
v interface{},
165-
variables map[string]interface{},
164+
v any,
165+
variables map[string]any,
166166
options ...Option,
167167
) (string, string, error) {
168168
query, err := query(v)
@@ -200,7 +200,7 @@ func ConstructSubscription(
200200
// queryArguments constructs a minified arguments string for variables.
201201
//
202202
// E.g., map[string]interface{}{"a": int(123), "b": true} -> "$a:Int!$b:Boolean!".
203-
func queryArguments(variables map[string]interface{}) string {
203+
func queryArguments(variables map[string]any) string {
204204
// Sort keys in order to produce deterministic output for testing purposes.
205205
// TODO: If tests can be made to work with non-deterministic output, then no need to sort.
206206
keys := make([]string, 0, len(variables))
@@ -228,7 +228,7 @@ func queryArguments(variables map[string]interface{}) string {
228228
// writeArgumentType writes a minified GraphQL type for t to w.
229229
// value indicates whether t is a value (required) type or pointer (optional) type.
230230
// If value is true, then "!" is written at the end of t.
231-
func writeArgumentType(w io.Writer, t reflect.Type, v interface{}, value bool) {
231+
func writeArgumentType(w io.Writer, t reflect.Type, v any, value bool) {
232232
if t.Implements(graphqlTypeInterface) {
233233
var graphqlType GraphQLType
234234
var ok bool
@@ -293,7 +293,7 @@ func writeArgumentType(w io.Writer, t reflect.Type, v interface{}, value bool) {
293293
// a minified query string from the provided struct v.
294294
//
295295
// E.g., struct{Foo Int, BarBaz *bool} -> "{foo,barBaz}".
296-
func query(v interface{}) (string, error) {
296+
func query(v any) (string, error) {
297297
var buf bytes.Buffer
298298

299299
err := writeQuery(&buf, reflect.TypeOf(v), reflect.ValueOf(v), false)

scalar.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ func NewBoolean(v Boolean) *Boolean { return &v }
4747
func NewFloat(v Float) *Float { return &v }
4848

4949
// NewID is a helper to make a new *ID.
50-
func NewID(v interface{}) *ID {
50+
func NewID(v any) *ID {
5151
rv := ToID(v)
5252

5353
return &rv
5454
}
5555

5656
// ToID is a helper for if you need to get the string version of an integer or
5757
// a string for the id.
58-
func ToID(v interface{}) ID {
58+
func ToID(v any) ID {
5959
var s string
6060
switch reflect.TypeOf(v).Kind() {
6161
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,

0 commit comments

Comments
 (0)