diff --git a/checks/cii_best_practices.go b/checks/cii_best_practices.go index 41993b2a969..d4678276a91 100644 --- a/checks/cii_best_practices.go +++ b/checks/cii_best_practices.go @@ -18,7 +18,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "math" "net/http" "strings" @@ -81,9 +81,9 @@ func CIIBestPractices(c *checker.CheckRequest) checker.CheckResult { } defer resp.Body.Close() - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { - e := sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("ioutil.ReadAll: %v", err)) + e := sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("io.ReadAll: %v", err)) return checker.CreateRuntimeErrorResult(CheckCIIBestPractices, e) } diff --git a/checks/fileparser/github_workflow_test.go b/checks/fileparser/github_workflow_test.go index 7f8bbeacfdd..6a0dc11e234 100644 --- a/checks/fileparser/github_workflow_test.go +++ b/checks/fileparser/github_workflow_test.go @@ -15,7 +15,7 @@ package fileparser import ( - "io/ioutil" + stdos "os" "testing" "github.com/rhysd/actionlint" @@ -109,7 +109,7 @@ func TestGitHubWorkflowShell(t *testing.T) { tt := tt // Re-initializing variable so it is not changed while executing the closure below t.Run(tt.name, func(t *testing.T) { t.Parallel() - content, err := ioutil.ReadFile(tt.filename) + content, err := stdos.ReadFile(tt.filename) if err != nil { t.Errorf("cannot read file: %v", err) } diff --git a/checks/permissions_test.go b/checks/permissions_test.go index 2e02ef4d2bb..de8f7390e40 100644 --- a/checks/permissions_test.go +++ b/checks/permissions_test.go @@ -16,7 +16,7 @@ package checks import ( "fmt" - "io/ioutil" + "os" "testing" "github.com/ossf/scorecard/v3/checker" @@ -251,7 +251,7 @@ func TestGithubTokenPermissions(t *testing.T) { if tt.filename == "" { content = make([]byte, 0) } else { - content, err = ioutil.ReadFile(tt.filename) + content, err = os.ReadFile(tt.filename) if err != nil { panic(fmt.Errorf("cannot read file: %w", err)) } diff --git a/checks/pinned_dependencies_test.go b/checks/pinned_dependencies_test.go index b1c3e0a021b..cb9d3bf4948 100644 --- a/checks/pinned_dependencies_test.go +++ b/checks/pinned_dependencies_test.go @@ -15,7 +15,7 @@ package checks import ( - "io/ioutil" + "os" "strings" "testing" @@ -105,7 +105,7 @@ func TestGithubWorkflowPinning(t *testing.T) { var content []byte var err error - content, err = ioutil.ReadFile(tt.filename) + content, err = os.ReadFile(tt.filename) if err != nil { t.Errorf("cannot read file: %v", err) } @@ -196,7 +196,7 @@ func TestNonGithubWorkflowPinning(t *testing.T) { if tt.filename == "" { content = make([]byte, 0) } else { - content, err = ioutil.ReadFile(tt.filename) + content, err = os.ReadFile(tt.filename) if err != nil { t.Errorf("cannot read file: %v", err) } @@ -241,7 +241,7 @@ func TestGithubWorkflowPkgManagerPinning(t *testing.T) { var content []byte var err error - content, err = ioutil.ReadFile(tt.filename) + content, err = os.ReadFile(tt.filename) if err != nil { t.Errorf("cannot read file: %v", err) } @@ -365,7 +365,7 @@ func TestDockerfilePinning(t *testing.T) { if tt.filename == "" { content = make([]byte, 0) } else { - content, err = ioutil.ReadFile(tt.filename) + content, err = os.ReadFile(tt.filename) if err != nil { t.Errorf("cannot read file: %v", err) } @@ -409,7 +409,7 @@ func TestDockerfilePinningWihoutHash(t *testing.T) { var content []byte var err error - content, err = ioutil.ReadFile(tt.filename) + content, err = os.ReadFile(tt.filename) if err != nil { t.Errorf("cannot read file: %v", err) } @@ -594,7 +594,7 @@ func TestDockerfileScriptDownload(t *testing.T) { if tt.filename == "" { content = make([]byte, 0) } else { - content, err = ioutil.ReadFile(tt.filename) + content, err = os.ReadFile(tt.filename) if err != nil { t.Errorf("cannot read file: %v", err) } @@ -638,7 +638,7 @@ func TestDockerfileScriptDownloadInfo(t *testing.T) { var content []byte var err error - content, err = ioutil.ReadFile(tt.filename) + content, err = os.ReadFile(tt.filename) if err != nil { t.Errorf("cannot read file: %v", err) } @@ -747,7 +747,7 @@ func TestShellScriptDownload(t *testing.T) { if tt.filename == "" { content = make([]byte, 0) } else { - content, err = ioutil.ReadFile(tt.filename) + content, err = os.ReadFile(tt.filename) if err != nil { t.Errorf("cannot read file: %v", err) } @@ -802,7 +802,7 @@ func TestShellScriptDownloadPinned(t *testing.T) { var content []byte var err error - content, err = ioutil.ReadFile(tt.filename) + content, err = os.ReadFile(tt.filename) if err != nil { t.Errorf("cannot read file: %v", err) } @@ -879,7 +879,7 @@ func TestGitHubWorflowRunDownload(t *testing.T) { if tt.filename == "" { content = make([]byte, 0) } else { - content, err = ioutil.ReadFile(tt.filename) + content, err = os.ReadFile(tt.filename) if err != nil { t.Errorf("cannot read file: %v", err) } @@ -942,7 +942,7 @@ func TestGitHubWorkflowUsesLineNumber(t *testing.T) { tt := tt // Re-initializing variable so it is not changed while executing the closure below t.Run(tt.name, func(t *testing.T) { t.Parallel() - content, err := ioutil.ReadFile(tt.filename) + content, err := os.ReadFile(tt.filename) if err != nil { t.Errorf("cannot read file: %v", err) } diff --git a/checks/shell_download_validate_test.go b/checks/shell_download_validate_test.go index 8e87970c8b3..1b26b18eb59 100644 --- a/checks/shell_download_validate_test.go +++ b/checks/shell_download_validate_test.go @@ -15,7 +15,7 @@ package checks import ( - "io/ioutil" + "os" "testing" ) @@ -75,7 +75,7 @@ func TestIsSupportedShellScriptFile(t *testing.T) { t.Parallel() var content []byte var err error - content, err = ioutil.ReadFile(tt.filename) + content, err = os.ReadFile(tt.filename) if err != nil { t.Errorf("cannot read file: %v", err) } diff --git a/clients/githubrepo/tarball.go b/clients/githubrepo/tarball.go index faa4b9983ad..70caf6925ac 100644 --- a/clients/githubrepo/tarball.go +++ b/clients/githubrepo/tarball.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -115,13 +114,13 @@ func (handler *tarballHandler) getTarball(ctx context.Context, repo *github.Repo } // Create a temp file. This automatically appends a random number to the name. - tempDir, err := ioutil.TempDir("", repoDir) + tempDir, err := os.MkdirTemp("", repoDir) if err != nil { - return fmt.Errorf("ioutil.TempDir: %w", err) + return fmt.Errorf("os.MkdirTemp: %w", err) } - repoFile, err := ioutil.TempFile(tempDir, repoFilename) + repoFile, err := os.CreateTemp(tempDir, repoFilename) if err != nil { - return fmt.Errorf("ioutil.TempFile: %w", err) + return fmt.Errorf("os.CreateTemp: %w", err) } defer repoFile.Close() if _, err := io.Copy(repoFile, resp.Body); err != nil { @@ -220,9 +219,9 @@ func (handler *tarballHandler) listFiles(predicate func(string) (bool, error)) ( } func (handler *tarballHandler) getFileContent(filename string) ([]byte, error) { - content, err := ioutil.ReadFile(filepath.Join(handler.tempDir, filename)) + content, err := os.ReadFile(filepath.Join(handler.tempDir, filename)) if err != nil { - return content, fmt.Errorf("ioutil.ReadFile: %w", err) + return content, fmt.Errorf("os.ReadFile: %w", err) } return content, nil } diff --git a/clients/githubrepo/tarball_test.go b/clients/githubrepo/tarball_test.go index dfa84090da4..9b9509fc79a 100644 --- a/clients/githubrepo/tarball_test.go +++ b/clients/githubrepo/tarball_test.go @@ -18,7 +18,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "strings" "testing" @@ -44,11 +43,11 @@ func isSortedString(x, y string) bool { } func setup(inputFile string) (tarballHandler, error) { - tempDir, err := ioutil.TempDir("", repoDir) + tempDir, err := os.MkdirTemp("", repoDir) if err != nil { return tarballHandler{}, fmt.Errorf("test failed to create TempDir: %w", err) } - tempFile, err := ioutil.TempFile(tempDir, repoFilename) + tempFile, err := os.CreateTemp(tempDir, repoFilename) if err != nil { return tarballHandler{}, fmt.Errorf("test failed to create TempFile: %w", err) } diff --git a/cron/bq/main.go b/cron/bq/main.go index 382e0f0448b..0f6090e7859 100644 --- a/cron/bq/main.go +++ b/cron/bq/main.go @@ -19,7 +19,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "log" "net/http" "strings" @@ -122,7 +122,7 @@ func transferDataToBq(ctx context.Context, return fmt.Errorf("error during http.Post to %s: %w", webhookURL, err) } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("error reading resp.Body: %w", err) } diff --git a/cron/config/config_test.go b/cron/config/config_test.go index df58816f1f4..4569944a0f7 100644 --- a/cron/config/config_test.go +++ b/cron/config/config_test.go @@ -16,7 +16,6 @@ package config import ( "errors" - "io/ioutil" "os" "testing" @@ -45,7 +44,7 @@ func getByteValueFromFile(filename string) ([]byte, error) { return nil, nil } //nolint - return ioutil.ReadFile(filename) + return os.ReadFile(filename) } func TestYAMLParsing(t *testing.T) { diff --git a/cron/data/update/dependency.go b/cron/data/update/dependency.go index f8d787f1ced..14021174fd7 100644 --- a/cron/data/update/dependency.go +++ b/cron/data/update/dependency.go @@ -19,7 +19,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "log" "os" "os/exec" @@ -123,7 +122,7 @@ func getGoDeps(repo repositoryDepsURL) []data.RepoFormat { //nolint defer os.Chdir(pwd) // creating temp dir for git clone - gitDir, err := ioutil.TempDir(pwd, "") + gitDir, err := os.MkdirTemp(pwd, "") if err != nil { log.Default().Println("Cannot create temporary dir", err) return nil diff --git a/cron/format/json_test.go b/cron/format/json_test.go index fbeb72f7a30..82e91b57c33 100644 --- a/cron/format/json_test.go +++ b/cron/format/json_test.go @@ -18,7 +18,6 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "os" "path" "testing" @@ -459,7 +458,7 @@ func TestJSONOutput(t *testing.T) { t.Parallel() var content []byte var err error - content, err = ioutil.ReadFile(tt.expected) + content, err = os.ReadFile(tt.expected) if err != nil { t.Fatalf("cannot read file: %v", err) } diff --git a/cron/webhook/main.go b/cron/webhook/main.go index 281d445f638..70162216b4c 100644 --- a/cron/webhook/main.go +++ b/cron/webhook/main.go @@ -18,7 +18,7 @@ package main import ( "fmt" - "io/ioutil" + "io" "log" "net/http" @@ -42,7 +42,7 @@ var images = []string{ func scriptHandler(w http.ResponseWriter, r *http.Request) { switch r.Method { case http.MethodPost: - jsonBytes, err := ioutil.ReadAll(r.Body) + jsonBytes, err := io.ReadAll(r.Body) if err != nil { http.Error(w, fmt.Sprintf("unable to read request body: %v", err), http.StatusInternalServerError) diff --git a/docs/checks/internal/validate/main.go b/docs/checks/internal/validate/main.go index 7abe22e3c9d..fd72f85a89d 100644 --- a/docs/checks/internal/validate/main.go +++ b/docs/checks/internal/validate/main.go @@ -15,7 +15,7 @@ package main import ( "fmt" - "io/ioutil" + "os" "path" "regexp" "strings" @@ -59,9 +59,9 @@ func listCheckFiles() (map[string]string, error) { // Use regex to determine the file that contains the entry point. // We're looking for `const someVarName = "CheckName"`. regex := regexp.MustCompile(`const\s+[^"]*=\s+"(.*)"`) - files, err := ioutil.ReadDir("checks/") + files, err := os.ReadDir("checks/") if err != nil { - return nil, fmt.Errorf("ioutil.ReadDir: %w", err) + return nil, fmt.Errorf("os.ReadDir: %w", err) } for _, file := range files { @@ -70,9 +70,9 @@ func listCheckFiles() (map[string]string, error) { } fullpath := path.Join("checks/", file.Name()) - content, err := ioutil.ReadFile(fullpath) + content, err := os.ReadFile(fullpath) if err != nil { - return nil, fmt.Errorf("ioutil.ReadFile: %s: %w", fullpath, err) + return nil, fmt.Errorf("os.ReadFile: %s: %w", fullpath, err) } res := regex.FindStringSubmatch(string(content)) @@ -94,9 +94,9 @@ func listCheckFiles() (map[string]string, error) { func extractAPINames() ([]string, error) { fns := []string{} interfaceRe := regexp.MustCompile(`type\s+RepoClient\s+interface\s+{\s*`) - content, err := ioutil.ReadFile("clients/repo_client.go") + content, err := os.ReadFile("clients/repo_client.go") if err != nil { - return nil, fmt.Errorf("ioutil.ReadFile: %s: %w", "clients/repo_client.go", err) + return nil, fmt.Errorf("os.ReadFile: %s: %w", "clients/repo_client.go", err) } locs := interfaceRe.FindIndex(content) @@ -152,9 +152,9 @@ func supportedInterfacesFromImplementation(checkName string, checkFiles map[stri return nil, fmt.Errorf("check %s does not exists", checkName) } - content, err := ioutil.ReadFile(pathfn) + content, err := os.ReadFile(pathfn) if err != nil { - return nil, fmt.Errorf("ioutil.ReadFile: %s: %w", pathfn, err) + return nil, fmt.Errorf("os.ReadFile: %s: %w", pathfn, err) } // For each API, check if it's used or not. diff --git a/e2e/executable_test.go b/e2e/executable_test.go index 247467a641a..7b3dbc2b96b 100644 --- a/e2e/executable_test.go +++ b/e2e/executable_test.go @@ -16,7 +16,7 @@ package e2e import ( "encoding/json" - "io/ioutil" + "os" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -39,7 +39,7 @@ type scorecard struct { var _ = Describe("E2E TEST:executable", func() { Context("E2E TEST:Validating executable test", func() { It("Should return valid test results for scorecard", func() { - file, err := ioutil.ReadFile("../output/results.json") + file, err := os.ReadFile("../output/results.json") Expect(err).Should(BeNil()) data := scorecard{} diff --git a/pkg/json_test.go b/pkg/json_test.go index 6e62a9c0d95..30662029aa9 100644 --- a/pkg/json_test.go +++ b/pkg/json_test.go @@ -18,7 +18,6 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "os" "path" "testing" @@ -458,7 +457,7 @@ func TestJSONOutput(t *testing.T) { t.Parallel() var content []byte var err error - content, err = ioutil.ReadFile(tt.expected) + content, err = os.ReadFile(tt.expected) if err != nil { t.Fatalf("cannot read file: %v", err) } diff --git a/pkg/sarif_test.go b/pkg/sarif_test.go index a13f27bc9cd..e9b049bf9e3 100644 --- a/pkg/sarif_test.go +++ b/pkg/sarif_test.go @@ -17,7 +17,7 @@ package pkg import ( "bytes" "fmt" - "io/ioutil" + "os" "testing" "time" @@ -774,7 +774,7 @@ func TestSARIFOutput(t *testing.T) { t.Parallel() var content []byte var err error - content, err = ioutil.ReadFile(tt.expected) + content, err = os.ReadFile(tt.expected) if err != nil { t.Fatalf("%s: cannot read file: %v", tt.name, err) } diff --git a/policy/policy_test.go b/policy/policy_test.go index 1ba78009e4e..3de3c45bbf6 100644 --- a/policy/policy_test.go +++ b/policy/policy_test.go @@ -16,7 +16,7 @@ package policy import ( "errors" - "io/ioutil" + "os" "testing" sce "github.com/ossf/scorecard/v3/errors" @@ -109,7 +109,7 @@ func TestPolicyRead(t *testing.T) { t.Parallel() var content []byte var err error - content, err = ioutil.ReadFile(tt.filename) + content, err = os.ReadFile(tt.filename) if err != nil { t.Fatalf("cannot read file: %v", err) }