Skip to content

Commit

Permalink
fix linter warnings (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
devsergiy authored Sep 26, 2023
1 parent bfb2eaa commit aa898c4
Show file tree
Hide file tree
Showing 30 changed files with 77 additions and 84 deletions.
3 changes: 1 addition & 2 deletions v2/examples/chat/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package chat

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -63,7 +62,7 @@ func LoadSchemaFromExamplesDirectoryWithinPkg() ([]byte, error) {
}

absolutePath := filepath.Join(strings.Split(wd, "pkg")[0], chatExampleDirectoryRelativePath, "schema.graphql")
return ioutil.ReadFile(absolutePath)
return os.ReadFile(absolutePath)
}

func GraphQLRequestForOperation(operation string) ([]byte, error) {
Expand Down
4 changes: 2 additions & 2 deletions v2/examples/federation/gateway/datasource_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"strings"
Expand Down Expand Up @@ -206,7 +206,7 @@ func (d *DatasourcePollerPoller) fetchServiceSDL(ctx context.Context, serviceURL
Errors GQLErr `json:"errors,omitempty"`
}

bs, err := ioutil.ReadAll(resp.Body)
bs, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("read bytes: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions v2/examples/kafka_pubsub/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"math/rand"
"os"
Expand Down Expand Up @@ -102,7 +102,7 @@ func main() {

// Parse command line parameters
f := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
f.SetOutput(ioutil.Discard)
f.SetOutput(io.Discard)
f.BoolVar(&args.help, "h", false, "")
f.BoolVar(&args.help, "help", false, "")
f.StringVar(&args.products, "p", "", "")
Expand Down
4 changes: 2 additions & 2 deletions v2/examples/kafka_pubsub/transactional_producer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"math/rand"
"os"
Expand Down Expand Up @@ -57,7 +57,7 @@ func main() {

// Parse command line parameters
f := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
f.SetOutput(ioutil.Discard)
f.SetOutput(io.Discard)
f.BoolVar(&args.help, "h", false, "")
f.BoolVar(&args.help, "help", false, "")
f.BoolVar(&args.enableTransaction, "enable-transaction", false, "")
Expand Down
4 changes: 2 additions & 2 deletions v2/internal/pkg/unsafeparser/unsafeparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package unsafeparser

import (
"io/ioutil"
"os"

"github.com/wundergraph/graphql-go-tools/v2/pkg/ast"
"github.com/wundergraph/graphql-go-tools/v2/pkg/astparser"
Expand All @@ -26,7 +26,7 @@ func ParseGraphqlDocumentBytes(input []byte) ast.Document {
}

func ParseGraphqlDocumentFile(filePath string) ast.Document {
fileBytes, err := ioutil.ReadFile(filePath)
fileBytes, err := os.ReadFile(filePath)
if err != nil {
panic(err)
}
Expand Down
10 changes: 5 additions & 5 deletions v2/pkg/astparser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package astparser

import (
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -2322,7 +2322,7 @@ func TestErrorReport(t *testing.T) {

func TestParseStarwars(t *testing.T) {

starWarsSchema, err := ioutil.ReadFile("./testdata/starwars.schema.graphql")
starWarsSchema, err := os.ReadFile("./testdata/starwars.schema.graphql")
if err != nil {
t.Fatal(err)
}
Expand All @@ -2336,7 +2336,7 @@ func TestParseStarwars(t *testing.T) {
func TestParseTodo(t *testing.T) {

inputFileName := "./testdata/todo.graphql"
schema, err := ioutil.ReadFile(inputFileName)
schema, err := os.ReadFile(inputFileName)
if err != nil {
t.Fatal(err)
}
Expand All @@ -2352,7 +2352,7 @@ func TestParseTodo(t *testing.T) {
func BenchmarkParseStarwars(b *testing.B) {

inputFileName := "./testdata/starwars.schema.graphql"
starwarsSchema, err := ioutil.ReadFile(inputFileName)
starwarsSchema, err := os.ReadFile(inputFileName)
if err != nil {
b.Fatal(err)
}
Expand All @@ -2379,7 +2379,7 @@ func BenchmarkParseStarwars(b *testing.B) {
func BenchmarkParseGithub(b *testing.B) {

inputFileName := "./testdata/github.schema.graphql"
schemaFile, err := ioutil.ReadFile(inputFileName)
schemaFile, err := os.ReadFile(inputFileName)
if err != nil {
b.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions v2/pkg/astprinter/astprinter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package astprinter

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/jensneuse/diffview"
Expand Down Expand Up @@ -533,7 +533,7 @@ func TestPrintSchemaDefinition(t *testing.T) {

goldie.Assert(t, "starwars_schema_definition", out)
if t.Failed() {
fixture, err := ioutil.ReadFile("./fixtures/starwars_schema_definition.golden")
fixture, err := os.ReadFile("./fixtures/starwars_schema_definition.golden")
if err != nil {
t.Fatal(err)
}
Expand All @@ -557,7 +557,7 @@ func TestPrintOperationDefinition(t *testing.T) {

goldie.Assert(t, "introspectionquery", out)
if t.Failed() {
fixture, err := ioutil.ReadFile("./fixtures/introspectionquery.golden")
fixture, err := os.ReadFile("./fixtures/introspectionquery.golden")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions v2/pkg/asttransform/baseschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package asttransform_test

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/jensneuse/diffview"
Expand All @@ -28,7 +28,7 @@ func runTestMerge(definition, fixtureName string) func(t *testing.T) {
got := buf.Bytes()
goldie.Assert(t, fixtureName, got)
if t.Failed() {
want, err := ioutil.ReadFile("./fixtures/" + fixtureName + ".golden")
want, err := os.ReadFile("./fixtures/" + fixtureName + ".golden")
if err != nil {
panic(err)
}
Expand Down
9 changes: 4 additions & 5 deletions v2/pkg/astvalidation/reference/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand All @@ -23,13 +22,13 @@ func main() {
workingDir = filepath.Join(currDir, "pkg/astvalidation/reference/__tests__")
}

dir, err := ioutil.ReadDir(workingDir)
dir, err := os.ReadDir(workingDir)
if err != nil {
log.Fatal(err)
}

replacementsPath := workingDir + "/../replacements.yml"
replacementContent, _ := ioutil.ReadFile(replacementsPath)
replacementContent, _ := os.ReadFile(replacementsPath)

var replacements []Replacement
if err := yaml.Unmarshal(replacementContent, &replacements); err != nil {
Expand Down Expand Up @@ -112,7 +111,7 @@ func skipRule(name string) bool {
// processFile - convert and save reference test file
func processFile(workingDir string, filename string, replacements Replacements) {
fPath := filepath.Join(workingDir, filename)
fileContent, _ := ioutil.ReadFile(fPath)
fileContent, _ := os.ReadFile(fPath)

testName := strings.TrimSuffix(strings.Split(filepath.Base(filename), ".")[0], "-test")

Expand All @@ -129,7 +128,7 @@ func processFile(workingDir string, filename string, replacements Replacements)
result := converter.iterateLines(testName, content)

outFileName := testName + "_test.go"
err := ioutil.WriteFile(filepath.Join(outDir, outFileName), []byte(result), os.ModePerm)
err := os.WriteFile(filepath.Join(outDir, outFileName), []byte(result), os.ModePerm)
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions v2/pkg/astvalidation/reference/testsgo/harness_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testsgo

import (
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -314,7 +314,7 @@ func hasReportError(t *testing.T, report operationreport.Report) MessageCompare
var testSchema string

func init() {
content, err := ioutil.ReadFile("test_schema.graphql")
content, err := os.ReadFile("test_schema.graphql")
if err != nil {
panic(err)
}
Expand Down
10 changes: 5 additions & 5 deletions v2/pkg/astvisitor/visitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"testing"

"github.com/jensneuse/diffview"
Expand Down Expand Up @@ -46,7 +46,7 @@ func TestVisitOperation(t *testing.T) {

if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/visitor.golden")
fixture, err := os.ReadFile("./fixtures/visitor.golden")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestVisitSchemaDefinition(t *testing.T) {

if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/schema_visitor.golden")
fixture, err := os.ReadFile("./fixtures/schema_visitor.golden")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func TestWalker_Path(t *testing.T) {

if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/path.golden")
fixture, err := os.ReadFile("./fixtures/path.golden")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestVisitWithSkip(t *testing.T) {

if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/visitor_skip.golden")
fixture, err := os.ReadFile("./fixtures/visitor_skip.golden")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions v2/pkg/codegen/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package codegen

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestCodeGen_GenerateDirectiveDefinitionStruct(t *testing.T) {
goldie.Assert(t, "DataSource", data)
if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/DataSource.golden")
fixture, err := os.ReadFile("./fixtures/DataSource.golden")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions v2/pkg/graphql/execution_engine_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"compress/gzip"
"context"
"errors"
"io/ioutil"
"io"
"net/http"
"strconv"
"sync"
Expand Down Expand Up @@ -96,7 +96,7 @@ func (e *EngineResultWriter) AsHTTPResponse(status int, headers http.Header) *ht
}

res := &http.Response{}
res.Body = ioutil.NopCloser(b)
res.Body = io.NopCloser(b)
res.Header = headers
res.StatusCode = status
res.ContentLength = int64(b.Len())
Expand Down
6 changes: 3 additions & 3 deletions v2/pkg/graphql/execution_engine_v2_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package graphql
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"testing"

Expand Down Expand Up @@ -34,14 +34,14 @@ func createTestRoundTripper(t *testing.T, testCase roundTripperTestCase) testRou
var receivedBodyBytes []byte
if req.Body != nil {
var err error
receivedBodyBytes, err = ioutil.ReadAll(req.Body)
receivedBodyBytes, err = io.ReadAll(req.Body)
require.NoError(t, err)
}
require.Equal(t, testCase.expectedBody, string(receivedBodyBytes), "roundTripperTestCase body do not match")
}

body := bytes.NewBuffer([]byte(testCase.sendResponseBody))
return &http.Response{StatusCode: testCase.sendStatusCode, Body: ioutil.NopCloser(body)}
return &http.Response{StatusCode: testCase.sendStatusCode, Body: io.NopCloser(body)}
}
}

Expand Down
8 changes: 4 additions & 4 deletions v2/pkg/graphql/execution_engine_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"compress/gzip"
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"sync"
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestEngineResponseWriter_AsHTTPResponse(t *testing.T) {
headers := make(http.Header)
headers.Set("Content-Type", "application/json")
response := rw.AsHTTPResponse(http.StatusOK, headers)
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
require.NoError(t, err)

assert.Equal(t, http.StatusOK, response.StatusCode)
Expand All @@ -71,7 +71,7 @@ func TestEngineResponseWriter_AsHTTPResponse(t *testing.T) {
reader, err := gzip.NewReader(response.Body)
require.NoError(t, err)

body, err := ioutil.ReadAll(reader)
body, err := io.ReadAll(reader)
require.NoError(t, err)

assert.Equal(t, `{"key": "value"}`, string(body))
Expand All @@ -86,7 +86,7 @@ func TestEngineResponseWriter_AsHTTPResponse(t *testing.T) {
assert.Equal(t, "deflate", response.Header.Get(httpclient.ContentEncodingHeader))

reader := flate.NewReader(response.Body)
body, err := ioutil.ReadAll(reader)
body, err := io.ReadAll(reader)
require.NoError(t, err)

assert.Equal(t, `{"key": "value"}`, string(body))
Expand Down
3 changes: 1 addition & 2 deletions v2/pkg/graphql/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"

"github.com/wundergraph/graphql-go-tools/v2/pkg/ast"
Expand Down Expand Up @@ -47,7 +46,7 @@ type Request struct {
}

func UnmarshalRequest(reader io.Reader, request *Request) error {
requestBytes, err := ioutil.ReadAll(reader)
requestBytes, err := io.ReadAll(reader)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit aa898c4

Please sign in to comment.