From 3c373d72d2985315ecdc6c471122477501fd0a19 Mon Sep 17 00:00:00 2001 From: Azeem Shaikh Date: Wed, 21 Sep 2022 16:34:21 +0000 Subject: [PATCH] Fix failing linters Signed-off-by: Azeem Shaikh --- .golangci.yml | 5 ----- checker/check_result.go | 2 ++ checks/fileparser/listing_test.go | 1 + checks/raw/branch_protection_test.go | 2 +- checks/raw/license_test.go | 1 + checks/raw/shell_download_validate.go | 2 +- clients/githubrepo/graphql.go | 2 +- clients/githubrepo/roundtripper/tokens/server/main.go | 1 + clients/githubrepo/tarball.go | 2 +- clients/githubrepo/tarball_test.go | 2 +- cmd/package_managers_test.go | 8 ++++---- cmd/packagemanager_client.go | 2 +- cmd/serve.go | 1 + cron/internal/data/update/main.go | 3 ++- cron/internal/webhook/main.go | 1 + cron/internal/worker/main.go | 3 ++- docs/checks/internal/generate/main.go | 2 +- docs/checks/internal/reader.go | 1 + e2e/binary_artifacts_test.go | 3 +-- e2e/dangerous_workflow_test.go | 5 ++--- e2e/license_test.go | 5 ++--- e2e/permissions_test.go | 3 +-- e2e/pinned_dependencies_test.go | 5 ++--- e2e/security_policy_test.go | 5 ++--- pkg/json.go | 7 ++++--- pkg/scorecard_test.go | 2 +- utests/utlib.go | 2 +- 27 files changed, 39 insertions(+), 39 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 7c38dcc8d43..5fbec07c714 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -18,7 +18,6 @@ linters: disable-all: true enable: - asciicheck - - bodyclose - deadcode - depguard - dogsled @@ -50,17 +49,13 @@ linters: - misspell - nakedret - nestif - - noctx - - nolintlint - paralleltest - predeclared - staticcheck - stylecheck - thelper - - tparallel - typecheck - unconvert - - unparam - unused - varcheck - whitespace diff --git a/checker/check_result.go b/checker/check_result.go index 1914982950d..2866d121f8c 100644 --- a/checker/check_result.go +++ b/checker/check_result.go @@ -64,6 +64,7 @@ const ( ) // CheckResult captures result from a check run. +// //nolint:govet type CheckResult struct { Name string @@ -94,6 +95,7 @@ type CheckDetail struct { // LogMessage is a structure that encapsulates detail's information. // This allows updating the definition easily. +// //nolint:govet type LogMessage struct { Text string // A short string explaining why the detail was recorded/logged. diff --git a/checks/fileparser/listing_test.go b/checks/fileparser/listing_test.go index 778a800eafe..ff14e0084fa 100644 --- a/checks/fileparser/listing_test.go +++ b/checks/fileparser/listing_test.go @@ -535,6 +535,7 @@ func TestOnMatchingFileContent(t *testing.T) { } // TestOnAllFilesDo tests the OnAllFilesDo function. +// //nolint:gocognit func TestOnAllFilesDo(t *testing.T) { t.Parallel() diff --git a/checks/raw/branch_protection_test.go b/checks/raw/branch_protection_test.go index 6abc820b3ce..71364c272df 100644 --- a/checks/raw/branch_protection_test.go +++ b/checks/raw/branch_protection_test.go @@ -33,7 +33,7 @@ var ( mainBranchName = "main" ) -//nolint: govet +// nolint: govet type branchArg struct { err error name string diff --git a/checks/raw/license_test.go b/checks/raw/license_test.go index 8f49fdb9221..a85634724c1 100644 --- a/checks/raw/license_test.go +++ b/checks/raw/license_test.go @@ -103,6 +103,7 @@ func TestLicenseFileCheck(t *testing.T) { }, } + //nolint: paralleltest for _, tt := range tests { tt := tt // Re-initializing variable so it is not changed while executing the closure below for _, ext := range tt.extensions { diff --git a/checks/raw/shell_download_validate.go b/checks/raw/shell_download_validate.go index 3af817c2d77..a7d77ef8f05 100644 --- a/checks/raw/shell_download_validate.go +++ b/checks/raw/shell_download_validate.go @@ -890,7 +890,7 @@ func validateShellFileAndRecord(pathfn string, startLine, endLine uint, content // TODO: support other interpreters. // Example: https://github.com/apache/airflow/blob/main/scripts/ci/kubernetes/ci_run_kubernetes_tests.sh#L75 // HOST_PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info[0]}.{sys.version_info[1]}")')`` - // nolinter + // nolint if ok && isShellInterpreterOrCommand([]string{i}) { start, end := getLine(startLine, endLine, node) e := validateShellFileAndRecord(pathfn, start, end, diff --git a/clients/githubrepo/graphql.go b/clients/githubrepo/graphql.go index b208aeadc91..91f53ceb057 100644 --- a/clients/githubrepo/graphql.go +++ b/clients/githubrepo/graphql.go @@ -322,7 +322,7 @@ func parseCheckRuns(data *checkRunsGraphqlData) checkRunCache { return checkCache } -//nolint:all +//nolint func commitsFrom(data *graphqlData, repoOwner, repoName string) ([]clients.Commit, error) { ret := make([]clients.Commit, 0) for _, commit := range data.Repository.Object.Commit.History.Nodes { diff --git a/clients/githubrepo/roundtripper/tokens/server/main.go b/clients/githubrepo/roundtripper/tokens/server/main.go index 4678dd5df77..178fa57967a 100644 --- a/clients/githubrepo/roundtripper/tokens/server/main.go +++ b/clients/githubrepo/roundtripper/tokens/server/main.go @@ -42,6 +42,7 @@ func main() { panic(err) } + //nolint: gosec // internal server. if err := http.Serve(l, nil); err != nil { panic(err) } diff --git a/clients/githubrepo/tarball.go b/clients/githubrepo/tarball.go index 36a5635a3ca..55505f4284e 100644 --- a/clients/githubrepo/tarball.go +++ b/clients/githubrepo/tarball.go @@ -155,7 +155,7 @@ func (handler *tarballHandler) getTarball() error { return nil } -//nolint: gocognit +// nolint: gocognit func (handler *tarballHandler) extractTarball() error { in, err := os.OpenFile(handler.tempTarFile, os.O_RDONLY, 0o644) if err != nil { diff --git a/clients/githubrepo/tarball_test.go b/clients/githubrepo/tarball_test.go index f0d71fbbfdd..be13c1866f6 100644 --- a/clients/githubrepo/tarball_test.go +++ b/clients/githubrepo/tarball_test.go @@ -71,7 +71,7 @@ func setup(inputFile string) (tarballHandler, error) { return tarballHandler, nil } -//nolint: gocognit +// nolint: gocognit func TestExtractTarball(t *testing.T) { t.Parallel() testcases := []struct { diff --git a/cmd/package_managers_test.go b/cmd/package_managers_test.go index 608ac9d9f96..1aedc6cabcc 100644 --- a/cmd/package_managers_test.go +++ b/cmd/package_managers_test.go @@ -18,7 +18,7 @@ package cmd import ( "bytes" "errors" - "io/ioutil" + "io" "net/http" "testing" @@ -143,7 +143,7 @@ func Test_fetchGitRepositoryFromNPM(t *testing.T) { return &http.Response{ StatusCode: 200, - Body: ioutil.NopCloser(bytes.NewBufferString(tt.args.result)), + Body: io.NopCloser(bytes.NewBufferString(tt.args.result)), }, nil }).AnyTimes() got, err := fetchGitRepositoryFromNPM(tt.args.packageName, p) @@ -423,7 +423,7 @@ func Test_fetchGitRepositoryFromPYPI(t *testing.T) { return &http.Response{ StatusCode: 200, - Body: ioutil.NopCloser(bytes.NewBufferString(tt.args.result)), + Body: io.NopCloser(bytes.NewBufferString(tt.args.result)), }, nil }).AnyTimes() got, err := fetchGitRepositoryFromPYPI(tt.args.packageName, p) @@ -692,7 +692,7 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) { return &http.Response{ StatusCode: 200, - Body: ioutil.NopCloser(bytes.NewBufferString(tt.args.result)), + Body: io.NopCloser(bytes.NewBufferString(tt.args.result)), }, nil }).AnyTimes() got, err := fetchGitRepositoryFromRubyGems(tt.args.packageName, p) diff --git a/cmd/packagemanager_client.go b/cmd/packagemanager_client.go index e14b6d2c03a..cf9b591975d 100644 --- a/cmd/packagemanager_client.go +++ b/cmd/packagemanager_client.go @@ -26,7 +26,7 @@ type packageManagerClient interface { type packageManager struct{} -//nolint: noctx +// nolint: noctx func (c *packageManager) Get(url, packageName string) (*http.Response, error) { const timeout = 10 client := &http.Client{ diff --git a/cmd/serve.go b/cmd/serve.go index 0771b520d88..078451e53a2 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -95,6 +95,7 @@ func serveCmd(o *options.Options) *cobra.Command { port = "8080" } fmt.Printf("Listening on localhost:%s\n", port) + //nolint: gosec // unsused. err = http.ListenAndServe(fmt.Sprintf("0.0.0.0:%s", port), nil) if err != nil { // TODO(log): Should this actually panic? diff --git a/cron/internal/data/update/main.go b/cron/internal/data/update/main.go index 8b5df908272..07d0d914b74 100644 --- a/cron/internal/data/update/main.go +++ b/cron/internal/data/update/main.go @@ -24,7 +24,8 @@ import ( // Adds "project=${PROJECT},dependency=true" to the repositories metadata. // Args: -// file path to old_projects.csv new_projects.csv +// +// file path to old_projects.csv new_projects.csv func main() { if len(os.Args) != 3 { panic("must provide 2 arguments") diff --git a/cron/internal/webhook/main.go b/cron/internal/webhook/main.go index b6fc889ac99..7b7f03bc7d4 100644 --- a/cron/internal/webhook/main.go +++ b/cron/internal/webhook/main.go @@ -81,6 +81,7 @@ func scriptHandler(w http.ResponseWriter, r *http.Request) { func main() { http.HandleFunc("/", scriptHandler) fmt.Printf("Starting HTTP server on port 8080 ...\n") + // nolint:gosec // internal server. if err := http.ListenAndServe(":8080", nil); err != nil { log.Fatal(err) } diff --git a/cron/internal/worker/main.go b/cron/internal/worker/main.go index b28a71e3e17..12787007d5d 100644 --- a/cron/internal/worker/main.go +++ b/cron/internal/worker/main.go @@ -50,7 +50,7 @@ const ( var ignoreRuntimeErrors = flag.Bool("ignoreRuntimeErrors", false, "if set to true any runtime errors will be ignored") -//nolint: gocognit +// nolint: gocognit func processRequest(ctx context.Context, batchRequest *data.ScorecardBatchRequest, blacklistedChecks []string, bucketURL, rawBucketURL, apiBucketURL string, @@ -267,6 +267,7 @@ func main() { // Exposed for monitoring runtime profiles go func() { // TODO(log): Previously Fatal. Need to handle the error here. + //nolint: gosec // internal server. logger.Info(fmt.Sprintf("%v", http.ListenAndServe(":8080", nil))) }() diff --git a/docs/checks/internal/generate/main.go b/docs/checks/internal/generate/main.go index 15c5b12367a..0d3cd72a3db 100644 --- a/docs/checks/internal/generate/main.go +++ b/docs/checks/internal/generate/main.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/docs/checks/internal/reader.go b/docs/checks/internal/reader.go index 563cb5644d7..4f262fa1fdf 100644 --- a/docs/checks/internal/reader.go +++ b/docs/checks/internal/reader.go @@ -27,6 +27,7 @@ import ( var checksYAML []byte // Check stores a check's information. +// //nolint:govet type Check struct { Risk string `yaml:"risk"` diff --git a/e2e/binary_artifacts_test.go b/e2e/binary_artifacts_test.go index 9a39a6789cf..236f7eae161 100644 --- a/e2e/binary_artifacts_test.go +++ b/e2e/binary_artifacts_test.go @@ -16,7 +16,6 @@ package e2e import ( "context" - "io/ioutil" "os" "github.com/go-git/go-git/v5" @@ -173,7 +172,7 @@ var _ = Describe("E2E TEST:"+checks.CheckBinaryArtifacts, func() { }) It("Should return binary artifacts present at commit in source code when using local repoClient", func() { // create temp dir - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") Expect(err).Should(BeNil()) defer os.RemoveAll(tmpDir) diff --git a/e2e/dangerous_workflow_test.go b/e2e/dangerous_workflow_test.go index aa377c7cbd9..4b0fdcc01aa 100644 --- a/e2e/dangerous_workflow_test.go +++ b/e2e/dangerous_workflow_test.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -15,7 +15,6 @@ package e2e import ( "context" - "io/ioutil" "os" "github.com/go-git/go-git/v5" @@ -83,7 +82,7 @@ var _ = Describe("E2E TEST:"+checks.CheckTokenPermissions, func() { It("Should return dangerous workflow for local repoClient", func() { dl := scut.TestDetailLogger{} - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") Expect(err).Should(BeNil()) defer os.RemoveAll(tmpDir) diff --git a/e2e/license_test.go b/e2e/license_test.go index 83a9a5f4cc1..31ed4924dfe 100644 --- a/e2e/license_test.go +++ b/e2e/license_test.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -15,7 +15,6 @@ package e2e import ( "context" - "io/ioutil" "os" "github.com/go-git/go-git/v5" @@ -85,7 +84,7 @@ var _ = Describe("E2E TEST:"+checks.CheckLicense, func() { It("Should return license check works for the local repoclient", func() { dl := scut.TestDetailLogger{} - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") Expect(err).Should(BeNil()) defer os.RemoveAll(tmpDir) diff --git a/e2e/permissions_test.go b/e2e/permissions_test.go index 7f25a03d718..4bed2107e19 100644 --- a/e2e/permissions_test.go +++ b/e2e/permissions_test.go @@ -15,7 +15,6 @@ package e2e import ( "context" - "io/ioutil" "os" "github.com/go-git/go-git/v5" @@ -85,7 +84,7 @@ var _ = Describe("E2E TEST:"+checks.CheckTokenPermissions, func() { It("Should return token permission for a local repo client", func() { dl := scut.TestDetailLogger{} - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") Expect(err).Should(BeNil()) defer os.RemoveAll(tmpDir) diff --git a/e2e/pinned_dependencies_test.go b/e2e/pinned_dependencies_test.go index e38f7374c61..aa6c08a2ed5 100644 --- a/e2e/pinned_dependencies_test.go +++ b/e2e/pinned_dependencies_test.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -15,7 +15,6 @@ package e2e import ( "context" - "io/ioutil" "os" "github.com/go-git/go-git/v5" @@ -87,7 +86,7 @@ var _ = Describe("E2E TEST:"+checks.CheckPinnedDependencies, func() { It("Should return dependencies check for a local repoClient", func() { dl := scut.TestDetailLogger{} - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") Expect(err).Should(BeNil()) defer os.RemoveAll(tmpDir) diff --git a/e2e/security_policy_test.go b/e2e/security_policy_test.go index 293e291640f..3a4b35dd425 100644 --- a/e2e/security_policy_test.go +++ b/e2e/security_policy_test.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -15,7 +15,6 @@ package e2e import ( "context" - "io/ioutil" "os" "github.com/go-git/go-git/v5" @@ -139,7 +138,7 @@ var _ = Describe("E2E TEST:"+checks.CheckSecurityPolicy, func() { It("Should return valid security policy for local repoClient at head", func() { dl := scut.TestDetailLogger{} - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") Expect(err).Should(BeNil()) defer os.RemoveAll(tmpDir) diff --git a/pkg/json.go b/pkg/json.go index 4806a0d704a..0159ea4d024 100644 --- a/pkg/json.go +++ b/pkg/json.go @@ -24,7 +24,7 @@ import ( "github.com/ossf/scorecard/v4/log" ) -//nolint +// nolint: govet type jsonCheckResult struct { Name string Details []string @@ -45,7 +45,7 @@ type jsonCheckDocumentationV2 struct { // Can be extended if needed. } -//nolint +// nolint: govet type jsonCheckResultV2 struct { Details []string `json:"details"` Score int `json:"score"` @@ -71,8 +71,9 @@ func (s jsonFloatScore) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%.1f", s)), nil } -//nolint:govet // JSONScorecardResultV2 exports results as JSON for new detail format. +// +//nolint:govet type JSONScorecardResultV2 struct { Date string `json:"date"` Repo jsonRepoV2 `json:"repo"` diff --git a/pkg/scorecard_test.go b/pkg/scorecard_test.go index 6d778a31cac..a06f6413821 100644 --- a/pkg/scorecard_test.go +++ b/pkg/scorecard_test.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/utests/utlib.go b/utests/utlib.go index 590614cb75f..5cfabd34760 100644 --- a/utests/utlib.go +++ b/utests/utlib.go @@ -99,7 +99,7 @@ func errCmp(e1, e2 error) bool { } // ValidateTestReturn validates expected TestReturn with actual checker.CheckResult values. -//nolint: thelper +// nolint: thelper func ValidateTestReturn( t *testing.T, name string,