From c92ed07082b4f888eec0c9d5e31d44499bcf5b44 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 2 Aug 2023 08:21:55 +1000 Subject: [PATCH] Appease linter --- pkg/commands/oscommands/copy.go | 11 ++++++++--- pkg/config/config_linux.go | 5 ++--- pkg/gui/controllers/workspace_reset_controller.go | 6 +++--- pkg/integration/clients/go_test.go | 3 +-- pkg/integration/components/runner.go | 3 +-- pkg/integration/tests/test_list_generator.go | 13 ++++++------- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/pkg/commands/oscommands/copy.go b/pkg/commands/oscommands/copy.go index e68d0cfce..aab460e47 100644 --- a/pkg/commands/oscommands/copy.go +++ b/pkg/commands/oscommands/copy.go @@ -3,7 +3,6 @@ package oscommands import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" ) @@ -106,7 +105,7 @@ func CopyDir(src string, dst string) (err error) { return //nolint: nakedret } - entries, err := ioutil.ReadDir(src) + entries, err := os.ReadDir(src) if err != nil { return //nolint: nakedret } @@ -121,8 +120,14 @@ func CopyDir(src string, dst string) (err error) { return //nolint: nakedret } } else { + var info os.FileInfo + info, err = entry.Info() + if err != nil { + return //nolint: nakedret + } + // Skip symlinks. - if entry.Mode()&os.ModeSymlink != 0 { + if info.Mode()&os.ModeSymlink != 0 { continue } diff --git a/pkg/config/config_linux.go b/pkg/config/config_linux.go index 7f6187ee3..892e58de3 100644 --- a/pkg/config/config_linux.go +++ b/pkg/config/config_linux.go @@ -1,18 +1,17 @@ package config import ( - "io/ioutil" "os" "strings" ) func isWSL() bool { - data, err := ioutil.ReadFile("/proc/sys/kernel/osrelease") + data, err := os.ReadFile("/proc/sys/kernel/osrelease") return err == nil && strings.Contains(string(data), "microsoft") } func isContainer() bool { - data, err := ioutil.ReadFile("/proc/1/cgroup") + data, err := os.ReadFile("/proc/1/cgroup") if strings.Contains(string(data), "docker") || strings.Contains(string(data), "/lxc/") || diff --git a/pkg/gui/controllers/workspace_reset_controller.go b/pkg/gui/controllers/workspace_reset_controller.go index 195a9699e..6b78c6ac9 100644 --- a/pkg/gui/controllers/workspace_reset_controller.go +++ b/pkg/gui/controllers/workspace_reset_controller.go @@ -195,7 +195,7 @@ func getExplodeImage(width int, height int, frame int, max int) string { var buf bytes.Buffer // Initialize RNG seed - rand.Seed(time.Now().UnixNano()) + random := rand.New(rand.NewSource(time.Now().UnixNano())) // calculate the center of explosion centerX, centerY := width/2, height/2 @@ -223,9 +223,9 @@ func getExplodeImage(width int, height int, frame int, max int) string { // if distance is less than radius and greater than innerRadius, draw explosion char if distance <= radius && distance >= innerRadius { // Make placement random and less likely as explosion progresses - if rand.Float64() > progress { + if random.Float64() > progress { // Pick a random explosion char - char := explosionChars[rand.Intn(len(explosionChars))] + char := explosionChars[random.Intn(len(explosionChars))] buf.WriteRune(char) } else { buf.WriteRune(' ') diff --git a/pkg/integration/clients/go_test.go b/pkg/integration/clients/go_test.go index 851059e15..18d8569bd 100644 --- a/pkg/integration/clients/go_test.go +++ b/pkg/integration/clients/go_test.go @@ -10,7 +10,6 @@ import ( "bytes" "errors" "io" - "io/ioutil" "os" "os/exec" "testing" @@ -82,7 +81,7 @@ func runCmdHeadless(cmd *exec.Cmd) error { return err } - _, _ = io.Copy(ioutil.Discard, f) + _, _ = io.Copy(io.Discard, f) if cmd.Wait() != nil { // return an error with the stderr output diff --git a/pkg/integration/components/runner.go b/pkg/integration/components/runner.go index 40921fee9..32acdf25f 100644 --- a/pkg/integration/components/runner.go +++ b/pkg/integration/components/runner.go @@ -2,7 +2,6 @@ package components import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -222,7 +221,7 @@ func findOrCreateDir(path string) { func deleteAndRecreateEmptyDir(path string) { // remove contents of integration test directory - dir, err := ioutil.ReadDir(path) + dir, err := os.ReadDir(path) if err != nil { if os.IsNotExist(err) { err = os.Mkdir(path, 0o777) diff --git a/pkg/integration/tests/test_list_generator.go b/pkg/integration/tests/test_list_generator.go index 294165cca..f616f90a3 100644 --- a/pkg/integration/tests/test_list_generator.go +++ b/pkg/integration/tests/test_list_generator.go @@ -12,7 +12,6 @@ import ( "fmt" "go/format" "io/fs" - "io/ioutil" "os" "strings" @@ -26,19 +25,19 @@ func main() { if err != nil { panic(err) } - if err := ioutil.WriteFile("test_list.go", formattedCode, 0o644); err != nil { + if err := os.WriteFile("test_list.go", formattedCode, 0o644); err != nil { panic(err) } } func generateCode() []byte { // traverse parent directory to get all subling directories - directories, err := ioutil.ReadDir("../tests") + directories, err := os.ReadDir("../tests") if err != nil { panic(err) } - directories = lo.Filter(directories, func(file os.FileInfo, _ int) bool { + directories = lo.Filter(directories, func(file fs.DirEntry, _ int) bool { // 'shared' is a special folder containing shared test code so we // ignore it here return file.IsDir() && file.Name() != "shared" @@ -62,8 +61,8 @@ func generateCode() []byte { return buf.Bytes() } -func appendDirTests(dir fs.FileInfo, buf *bytes.Buffer) { - files, err := ioutil.ReadDir(fmt.Sprintf("../tests/%s", dir.Name())) +func appendDirTests(dir fs.DirEntry, buf *bytes.Buffer) { + files, err := os.ReadDir(fmt.Sprintf("../tests/%s", dir.Name())) if err != nil { panic(err) } @@ -77,7 +76,7 @@ func appendDirTests(dir fs.FileInfo, buf *bytes.Buffer) { strings.TrimSuffix(file.Name(), ".go"), ) - fileContents, err := ioutil.ReadFile(fmt.Sprintf("../tests/%s/%s", dir.Name(), file.Name())) + fileContents, err := os.ReadFile(fmt.Sprintf("../tests/%s/%s", dir.Name(), file.Name())) if err != nil { panic(err) }