Skip to content

Commit

Permalink
remove deprecated funcs usages (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
isopov authored Dec 7, 2023
1 parent 4a3073c commit 7f94c38
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ the the function call is excluded only if the type of the first argument is `TYP

An example of an exclude file is:

io/ioutil.ReadFile
io.Copy(*bytes.Buffer)
io.Copy(os.Stdout)
os.ReadFile

// Sometimes we don't care if a HTTP request fails.
(*net/http.Client).Do
Expand Down
27 changes: 13 additions & 14 deletions errcheck/errcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package errcheck

import (
"fmt"
"io/ioutil"
"os"
"path"
"regexp"
Expand Down Expand Up @@ -120,7 +119,7 @@ package custom
`
)

tmpGopath, err := ioutil.TempDir("", "testbuildtags")
tmpGopath, err := os.MkdirTemp("", "testbuildtags")
if err != nil {
t.Fatalf("unable to create testbuildtags directory: %v", err)
}
Expand All @@ -132,16 +131,16 @@ package custom
os.RemoveAll(tmpGopath)
}()

if err := ioutil.WriteFile(path.Join(testBuildTagsDir, "go.mod"), []byte("module github.com/testbuildtags"), 0644); err != nil {
if err := os.WriteFile(path.Join(testBuildTagsDir, "go.mod"), []byte("module github.com/testbuildtags"), 0644); err != nil {
t.Fatalf("Failed to write testbuildtags go.mod: %v", err)
}
if err := ioutil.WriteFile(path.Join(testBuildTagsDir, "custom1.go"), []byte(testBuildCustom1Tag), 0644); err != nil {
if err := os.WriteFile(path.Join(testBuildTagsDir, "custom1.go"), []byte(testBuildCustom1Tag), 0644); err != nil {
t.Fatalf("Failed to write testbuildtags custom1: %v", err)
}
if err := ioutil.WriteFile(path.Join(testBuildTagsDir, "custom2.go"), []byte(testBuildCustom2Tag), 0644); err != nil {
if err := os.WriteFile(path.Join(testBuildTagsDir, "custom2.go"), []byte(testBuildCustom2Tag), 0644); err != nil {
t.Fatalf("Failed to write testbuildtags custom2: %v", err)
}
if err := ioutil.WriteFile(path.Join(testBuildTagsDir, "doc.go"), []byte(testDoc), 0644); err != nil {
if err := os.WriteFile(path.Join(testBuildTagsDir, "doc.go"), []byte(testDoc), 0644); err != nil {
t.Fatalf("Failed to write testbuildtags doc: %v", err)
}

Expand Down Expand Up @@ -229,7 +228,7 @@ require github.com/testlog v0.0.0
}`

// copy testvendor directory into directory for test
tmpGopath, err := ioutil.TempDir("", "testvendor")
tmpGopath, err := os.MkdirTemp("", "testvendor")
if err != nil {
t.Fatalf("unable to create testvendor directory: %v", err)
}
Expand All @@ -241,16 +240,16 @@ require github.com/testlog v0.0.0
os.RemoveAll(tmpGopath)
}()

if err := ioutil.WriteFile(path.Join(testVendorDir, "go.mod"), []byte(testVendorGoMod), 0755); err != nil {
if err := os.WriteFile(path.Join(testVendorDir, "go.mod"), []byte(testVendorGoMod), 0755); err != nil {
t.Fatalf("Failed to write testvendor go.mod: %v", err)
}
if err := ioutil.WriteFile(path.Join(testVendorDir, "main.go"), []byte(testVendorMain), 0755); err != nil {
if err := os.WriteFile(path.Join(testVendorDir, "main.go"), []byte(testVendorMain), 0755); err != nil {
t.Fatalf("Failed to write testvendor main: %v", err)
}
if err := os.MkdirAll(path.Join(testVendorDir, "vendor/github.com/testlog"), 0755); err != nil {
t.Fatalf("MkdirAll failed: %v", err)
}
if err := ioutil.WriteFile(path.Join(testVendorDir, "vendor/github.com/testlog/testlog.go"), []byte(testLog), 0755); err != nil {
if err := os.WriteFile(path.Join(testVendorDir, "vendor/github.com/testlog/testlog.go"), []byte(testLog), 0755); err != nil {
t.Fatalf("Failed to write testlog: %v", err)
}

Expand Down Expand Up @@ -336,7 +335,7 @@ require github.com/testlog v0.0.0
}`

// copy testvendor directory into directory for test
tmpGopath, err := ioutil.TempDir("", "testvendor")
tmpGopath, err := os.MkdirTemp("", "testvendor")
if err != nil {
t.Fatalf("unable to create testvendor directory: %v", err)
}
Expand All @@ -348,16 +347,16 @@ require github.com/testlog v0.0.0
os.RemoveAll(tmpGopath)
}()

if err := ioutil.WriteFile(path.Join(testVendorDir, "go.mod"), []byte(testVendorGoMod), 0755); err != nil {
if err := os.WriteFile(path.Join(testVendorDir, "go.mod"), []byte(testVendorGoMod), 0755); err != nil {
t.Fatalf("Failed to write testvendor go.mod: %v", err)
}
if err := ioutil.WriteFile(path.Join(testVendorDir, "main.go"), []byte(testVendorMain), 0755); err != nil {
if err := os.WriteFile(path.Join(testVendorDir, "main.go"), []byte(testVendorMain), 0755); err != nil {
t.Fatalf("Failed to write testvendor main: %v", err)
}
if err := os.MkdirAll(path.Join(testVendorDir, "vendor/github.com/testlog"), 0755); err != nil {
t.Fatalf("MkdirAll failed: %v", err)
}
if err := ioutil.WriteFile(path.Join(testVendorDir, "vendor/github.com/testlog/testlog.go"), []byte(testLog), 0755); err != nil {
if err := os.WriteFile(path.Join(testVendorDir, "vendor/github.com/testlog/testlog.go"), []byte(testLog), 0755); err != nil {
t.Fatalf("Failed to write testlog: %v", err)
}

Expand Down
4 changes: 2 additions & 2 deletions errcheck/excludes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package errcheck
import (
"bufio"
"bytes"
"io/ioutil"
"os"
"strings"
)

Expand Down Expand Up @@ -56,7 +56,7 @@ var DefaultExcludedSymbols = []string{
func ReadExcludes(path string) ([]string, error) {
var excludes []string

buf, err := ioutil.ReadFile(path)
buf, err := os.ReadFile(path)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions errcheck/testdata/src/a/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"bytes"
"crypto/sha256"
"fmt"
"io/ioutil"
"math/rand"
mrand "math/rand"
"os"
)

func a() error {
Expand Down Expand Up @@ -150,7 +150,7 @@ func main() {
mrand.Read(nil)
sha256.New().Write([]byte{})

ioutil.ReadFile("main.go") // want "unchecked error"
os.ReadFile("main.go") // want "unchecked error"

var emiw ErrorMakerInterfaceWrapper
emiw.MakeNilError() // want "unchecked error"
Expand Down
4 changes: 2 additions & 2 deletions testdata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
"math/rand"
mrand "math/rand"
"os"
)

func a() error {
Expand Down Expand Up @@ -152,7 +152,7 @@ func main() {
pr.CloseWithError(nil)
pw.CloseWithError(nil)

ioutil.ReadFile("main.go") // UNCHECKED
os.ReadFile("main.go") // UNCHECKED

var emiw ErrorMakerInterfaceWrapper
emiw.MakeNilError()
Expand Down
5 changes: 2 additions & 3 deletions testdata/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package main
import (
"bytes"
"crypto/sha256"
"io/ioutil"
"math/rand"
mrand "math/rand"

"os"
"testing"
)

Expand Down Expand Up @@ -84,7 +83,7 @@ func TestFunc(tt *testing.T) {
mrand.Read(nil)
sha256.New().Write([]byte{})

ioutil.ReadFile("main.go") // UNCHECKED
os.ReadFile("main.go") // UNCHECKED

var emiw ErrorMakerInterfaceWrapper
emiw.MakeNilError()
Expand Down

0 comments on commit 7f94c38

Please sign in to comment.