From 777dabde381c1c4b1b6bb0316658f65cce22c654 Mon Sep 17 00:00:00 2001 From: Michael Tibben Date: Mon, 13 Sep 2021 17:27:42 +1000 Subject: [PATCH 1/2] Update the linter --- .github/workflows/check-linting | 8 -------- .github/workflows/lint.yml | 5 +++-- 2 files changed, 3 insertions(+), 10 deletions(-) delete mode 100755 .github/workflows/check-linting diff --git a/.github/workflows/check-linting b/.github/workflows/check-linting deleted file mode 100755 index b7b771bcb35..00000000000 --- a/.github/workflows/check-linting +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -mkdir /tmp/golangci -curl -sL --fail https://github.com/golangci/golangci-lint/releases/download/v1.29.0/golangci-lint-1.29.0-linux-amd64.tar.gz | tar zxv --strip-components=1 --dir=/tmp/golangci - -/tmp/golangci/golangci-lint run diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 44695d14b86..0c2e46242fd 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,13 +5,14 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: { go-version: 1.17 } - run: go mod download - run: .github/workflows/check-fmt - - run: .github/workflows/check-linting - run: .github/workflows/check-generate + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 coverage: runs-on: ubuntu-latest From 85e7a4a0aae4c80c8522350d17400184fac48882 Mon Sep 17 00:00:00 2001 From: Michael Tibben Date: Mon, 13 Sep 2021 17:34:21 +1000 Subject: [PATCH 2/2] Linting fixes --- .golangci.yml | 2 +- client/websocket.go | 2 +- codegen/args.go | 2 +- codegen/config/config.go | 2 +- codegen/directive.go | 4 ++-- codegen/templates/templates.go | 4 ++-- codegen/util.go | 4 ++-- graphql/handler/transport/websocket_test.go | 2 +- internal/code/compare.go | 1 - internal/imports/prune_test.go | 2 +- internal/rewrite/rewriter_test.go | 2 +- plugin/resolvergen/resolver.go | 2 +- 12 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 8d513868009..21099b69b05 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,12 +21,12 @@ linters: - gosimple - govet - ineffassign - - interfacer - misspell - nakedret - prealloc - staticcheck - structcheck + - typecheck - unconvert - unused - varcheck diff --git a/client/websocket.go b/client/websocket.go index ca6ee7c4723..996ec7848c8 100644 --- a/client/websocket.go +++ b/client/websocket.go @@ -62,7 +62,7 @@ func (p *Client) WebsocketWithPayload(query string, initPayload map[string]inter } srv := httptest.NewServer(p.h) - host := strings.Replace(srv.URL, "http://", "ws://", -1) + host := strings.ReplaceAll(srv.URL, "http://", "ws://") c, _, err := websocket.DefaultDialer.Dial(host+r.URL.Path, r.Header) if err != nil { diff --git a/codegen/args.go b/codegen/args.go index 09254262aef..69af1404174 100644 --- a/codegen/args.go +++ b/codegen/args.go @@ -25,7 +25,7 @@ type FieldArgument struct { Value interface{} // value set in Data } -//ImplDirectives get not Builtin and location ARGUMENT_DEFINITION directive +// ImplDirectives get not Builtin and location ARGUMENT_DEFINITION directive func (f *FieldArgument) ImplDirectives() []*Directive { d := make([]*Directive, 0) for i := range f.Directives { diff --git a/codegen/config/config.go b/codegen/config/config.go index d29630d027e..29161a622a6 100644 --- a/codegen/config/config.go +++ b/codegen/config/config.go @@ -31,7 +31,7 @@ type Config struct { Packages *code.Packages `yaml:"-"` Schema *ast.Schema `yaml:"-"` - // Deprecated use Federation instead. Will be removed next release + // Deprecated: use Federation instead. Will be removed next release Federated bool `yaml:"federated,omitempty"` } diff --git a/codegen/directive.go b/codegen/directive.go index 2be102c2ca0..973061129a2 100644 --- a/codegen/directive.go +++ b/codegen/directive.go @@ -11,7 +11,7 @@ import ( type DirectiveList map[string]*Directive -//LocationDirectives filter directives by location +// LocationDirectives filter directives by location func (dl DirectiveList) LocationDirectives(location string) DirectiveList { return locationDirectives(dl, ast.DirectiveLocation(location)) } @@ -23,7 +23,7 @@ type Directive struct { Builtin bool } -//IsLocation check location directive +// IsLocation check location directive func (d *Directive) IsLocation(location ...ast.DirectiveLocation) bool { for _, l := range d.Locations { for _, a := range location { diff --git a/codegen/templates/templates.go b/codegen/templates/templates.go index 637b43515dc..3518a48d026 100644 --- a/codegen/templates/templates.go +++ b/codegen/templates/templates.go @@ -486,7 +486,7 @@ var commonInitialisms = map[string]bool{ } func rawQuote(s string) string { - return "`" + strings.Replace(s, "`", "`+\"`\"+`", -1) + "`" + return "`" + strings.ReplaceAll(s, "`", "`+\"`\"+`") + "`" } func notNil(field string, data interface{}) bool { @@ -548,7 +548,7 @@ func Dump(val interface{}) string { } func prefixLines(prefix, s string) string { - return prefix + strings.Replace(s, "\n", "\n"+prefix, -1) + return prefix + strings.ReplaceAll(s, "\n", "\n"+prefix) } func resolveName(name string, skip int) string { diff --git a/codegen/util.go b/codegen/util.go index d1c4533809a..fa2ceed3dfe 100644 --- a/codegen/util.go +++ b/codegen/util.go @@ -40,7 +40,7 @@ func findGoInterface(def types.Type) (*types.Interface, error) { } func equalFieldName(source, target string) bool { - source = strings.Replace(source, "_", "", -1) - target = strings.Replace(target, "_", "", -1) + source = strings.ReplaceAll(source, "_", "") + target = strings.ReplaceAll(target, "_", "") return strings.EqualFold(source, target) } diff --git a/graphql/handler/transport/websocket_test.go b/graphql/handler/transport/websocket_test.go index a02fb17002d..566777b621a 100644 --- a/graphql/handler/transport/websocket_test.go +++ b/graphql/handler/transport/websocket_test.go @@ -268,7 +268,7 @@ func TestWebsocketInitFunc(t *testing.T) { } func wsConnect(url string) *websocket.Conn { - c, resp, err := websocket.DefaultDialer.Dial(strings.Replace(url, "http://", "ws://", -1), nil) + c, resp, err := websocket.DefaultDialer.Dial(strings.ReplaceAll(url, "http://", "ws://"), nil) if err != nil { panic(err) } diff --git a/internal/code/compare.go b/internal/code/compare.go index dce9aea558f..dda434154c1 100644 --- a/internal/code/compare.go +++ b/internal/code/compare.go @@ -7,7 +7,6 @@ import ( // CompatibleTypes isnt a strict comparison, it allows for pointer differences func CompatibleTypes(expected types.Type, actual types.Type) error { - //fmt.Println("Comparing ", expected.String(), actual.String()) // Special case to deal with pointer mismatches { diff --git a/internal/imports/prune_test.go b/internal/imports/prune_test.go index 26ff109fc52..b7205fbedda 100644 --- a/internal/imports/prune_test.go +++ b/internal/imports/prune_test.go @@ -14,7 +14,7 @@ func TestPrune(t *testing.T) { b, err := Prune("testdata/unused.go", mustReadFile("testdata/unused.go"), &code.Packages{}) require.NoError(t, err) - require.Equal(t, strings.Replace(string(mustReadFile("testdata/unused.expected.go")), "\r\n", "\n", -1), string(b)) + require.Equal(t, strings.ReplaceAll(string(mustReadFile("testdata/unused.expected.go")), "\r\n", "\n"), string(b)) } func mustReadFile(filename string) []byte { diff --git a/internal/rewrite/rewriter_test.go b/internal/rewrite/rewriter_test.go index bd9968eadcf..202c6938b3a 100644 --- a/internal/rewrite/rewriter_test.go +++ b/internal/rewrite/rewriter_test.go @@ -21,7 +21,7 @@ func TestRewriter(t *testing.T) { m.Field++ // trailing comment -`, strings.Replace(body, "\r\n", "\n", -1)) +`, strings.ReplaceAll(body, "\r\n", "\n")) imps := r.ExistingImports("testdata/example.go") require.Len(t, imps, 2) diff --git a/plugin/resolvergen/resolver.go b/plugin/resolvergen/resolver.go index e63501d2bc6..b4985426246 100644 --- a/plugin/resolvergen/resolver.go +++ b/plugin/resolvergen/resolver.go @@ -173,7 +173,7 @@ type ResolverBuild struct { type File struct { // These are separated because the type definition of the resolver object may live in a different file from the - //resolver method implementations, for example when extending a type in a different graphql schema file + // resolver method implementations, for example when extending a type in a different graphql schema file Objects []*codegen.Object Resolvers []*Resolver imports []rewrite.Import