diff --git a/.golangci.yml b/.golangci.yml index b4b4e505264..350c4328101 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -18,6 +18,9 @@ issues: - funlen - goconst - gocyclo + - goerr113 + - lll + - wrapcheck skip-files: - cron/data/request.pb.go # autogenerated linters: diff --git a/checker/check_result_test.go b/checker/check_result_test.go index 42cc8a66823..cf792232704 100644 --- a/checker/check_result_test.go +++ b/checker/check_result_test.go @@ -545,7 +545,7 @@ func TestCreateProportionalScoreResult(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - if got := CreateProportionalScoreResult(tt.args.name, tt.args.reason, tt.args.b, tt.args.t); !cmp.Equal(got, tt.want) { //nolint:lll + if got := CreateProportionalScoreResult(tt.args.name, tt.args.reason, tt.args.b, tt.args.t); !cmp.Equal(got, tt.want) { t.Errorf("CreateProportionalScoreResult() = %v, want %v", got, cmp.Diff(got, tt.want)) } }) @@ -714,14 +714,14 @@ func TestCreateRuntimeErrorResult(t *testing.T) { name: "empty", args: args{ name: "", - e: errors.New("runtime error"), //nolint:goerr113 + e: errors.New("runtime error"), }, want: CheckResult{ Name: "", Reason: "runtime error", Score: -1, Version: 2, - Error: errors.New("runtime error"), //nolint:goerr113 + Error: errors.New("runtime error"), }, }, } diff --git a/checker/client_test.go b/checker/client_test.go index c1caf79cf13..9426e841bdb 100644 --- a/checker/client_test.go +++ b/checker/client_test.go @@ -106,7 +106,7 @@ func TestGetClients(t *testing.T) { t.Setenv("GH_HOST", "github.corp.com") t.Setenv("GH_TOKEN", "PAT") } - got, repoClient, ossFuzzClient, ciiClient, vulnsClient, err := GetClients(tt.args.ctx, tt.args.repoURI, tt.args.localURI, tt.args.logger) //nolint:lll + got, repoClient, ossFuzzClient, ciiClient, vulnsClient, err := GetClients(tt.args.ctx, tt.args.repoURI, tt.args.localURI, tt.args.logger) if (err != nil) != tt.wantErr { t.Fatalf("GetClients() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/checks/ci_tests_test.go b/checks/ci_tests_test.go index 8e19820e3c2..7acb4bb1810 100644 --- a/checks/ci_tests_test.go +++ b/checks/ci_tests_test.go @@ -29,7 +29,6 @@ func TestCITestsRuntimeError(t *testing.T) { ctrl := gomock.NewController(t) mockRepoClient := mockrepo.NewMockRepoClient(ctrl) - //nolint:goerr113 mockRepoClient.EXPECT().ListCommits().Return(nil, fmt.Errorf("some runtime error")).AnyTimes() req := checker.CheckRequest{ diff --git a/checks/code_review_test.go b/checks/code_review_test.go index 81d5d3675ad..1a384c6bd9e 100644 --- a/checks/code_review_test.go +++ b/checks/code_review_test.go @@ -30,7 +30,6 @@ import ( // TestCodeReview tests the code review checker. func TestCodereview(t *testing.T) { t.Parallel() - //nolint:goerr113 tests := []struct { err error name string diff --git a/checks/contributors_test.go b/checks/contributors_test.go index 9c162cff339..2ab795374c4 100644 --- a/checks/contributors_test.go +++ b/checks/contributors_test.go @@ -143,7 +143,7 @@ func TestContributors(t *testing.T) { }, }, { - err: errors.New("error"), //nolint:goerr113 + err: errors.New("error"), name: "Error getting contributors", contrib: []clients.User{}, expected: checker.CheckResult{ diff --git a/checks/evaluation/ci_tests_test.go b/checks/evaluation/ci_tests_test.go index 22ddae1e14b..19e20d3668c 100644 --- a/checks/evaluation/ci_tests_test.go +++ b/checks/evaluation/ci_tests_test.go @@ -192,8 +192,10 @@ func Test_prHasSuccessfulCheck(t *testing.T) { tt := tt dl := &scut.TestDetailLogger{} - //nolint:errcheck - got, _ := prHasSuccessfulCheck(tt.args, dl) + got, err := prHasSuccessfulCheck(tt.args, dl) + if err != nil { + t.Fatalf("unexpected err: %v", err) + } if got != tt.want { t.Errorf("prHasSuccessfulCheck() = %v, want %v", got, tt.want) } diff --git a/checks/fileparser/listing_test.go b/checks/fileparser/listing_test.go index 86bbc74d0e0..bb4e619b7aa 100644 --- a/checks/fileparser/listing_test.go +++ b/checks/fileparser/listing_test.go @@ -515,7 +515,6 @@ func TestOnMatchingFileContent(t *testing.T) { t.Parallel() x := func(path string, content []byte, args ...interface{}) (bool, error) { if tt.shouldFuncFail { - //nolint:goerr113 return false, errors.New("test error") } if tt.shouldGetPredicateFail { diff --git a/checks/fuzzing_test.go b/checks/fuzzing_test.go index ca909758ea4..c4f9a3f3f32 100644 --- a/checks/fuzzing_test.go +++ b/checks/fuzzing_test.go @@ -139,7 +139,6 @@ func TestFuzzing(t *testing.T) { mockFuzz.EXPECT().Search(gomock.Any()). DoAndReturn(func(q clients.SearchRequest) (clients.SearchResponse, error) { if tt.wantErr { - //nolint:goerr113 return clients.SearchResponse{}, errors.New("error") } return tt.response, nil @@ -148,7 +147,6 @@ func TestFuzzing(t *testing.T) { mockFuzz.EXPECT().ListFiles(gomock.Any()).Return(tt.fileName, nil).AnyTimes() mockFuzz.EXPECT().GetFileContent(gomock.Any()).DoAndReturn(func(f string) (string, error) { if tt.wantErr { - //nolint:goerr113 return "", errors.New("error") } return tt.fileContent, nil diff --git a/checks/maintained_test.go b/checks/maintained_test.go index d9fb337ae67..d47696e26e5 100644 --- a/checks/maintained_test.go +++ b/checks/maintained_test.go @@ -44,7 +44,7 @@ func Test_Maintained(t *testing.T) { otheruser := clients.User{ Login: "someone-else", } - //nolint:govet,goerr113 + //nolint:govet tests := []struct { err error name string diff --git a/checks/permissions_test.go b/checks/permissions_test.go index 0e72315608c..9261fb2792d 100644 --- a/checks/permissions_test.go +++ b/checks/permissions_test.go @@ -28,7 +28,6 @@ import ( scut "github.com/ossf/scorecard/v4/utests" ) -//nolint:lll func TestGithubTokenPermissions(t *testing.T) { t.Parallel() diff --git a/checks/raw/fuzzing_test.go b/checks/raw/fuzzing_test.go index d69430d8995..e409b401447 100644 --- a/checks/raw/fuzzing_test.go +++ b/checks/raw/fuzzing_test.go @@ -76,7 +76,6 @@ func Test_checkOSSFuzz(t *testing.T) { mockFuzz.EXPECT().Search(gomock.Any()). DoAndReturn(func(q clients.SearchRequest) (clients.SearchResponse, error) { if tt.wantErr { - //nolint:goerr113 return clients.SearchResponse{}, errors.New("error") } return tt.response, nil @@ -138,7 +137,6 @@ func Test_checkCFLite(t *testing.T) { mockFuzz.EXPECT().ListFiles(gomock.Any()).Return(tt.fileName, nil).AnyTimes() mockFuzz.EXPECT().GetFileContent(gomock.Any()).DoAndReturn(func(f string) (string, error) { if tt.wantErr { - //nolint:goerr113 return "", errors.New("error") } return tt.fileContent, nil @@ -490,7 +488,6 @@ func Test_checkFuzzFunc(t *testing.T) { mockClient.EXPECT().ListFiles(gomock.Any()).Return(tt.fileName, nil).AnyTimes() mockClient.EXPECT().GetFileContent(gomock.Any()).DoAndReturn(func(f string) ([]byte, error) { if tt.wantErr { - //nolint:goerr113 return nil, errors.New("error") } return []byte(tt.fileContent), nil diff --git a/checks/raw/gitlab/packaging_test.go b/checks/raw/gitlab/packaging_test.go index d300d20a62d..1e66f045200 100644 --- a/checks/raw/gitlab/packaging_test.go +++ b/checks/raw/gitlab/packaging_test.go @@ -136,9 +136,8 @@ func TestGitlabPackagingPackager(t *testing.T) { moqRepoClient.EXPECT().GetFileContent(tt.filename). DoAndReturn(func(b string) ([]byte, error) { - //nolint:errcheck - content, _ := os.ReadFile(b) - return content, nil + content, err := os.ReadFile(b) + return content, err }).AnyTimes() if tt.exists { @@ -150,8 +149,10 @@ func TestGitlabPackagingPackager(t *testing.T) { Repo: moqRepo, } - //nolint:errcheck - packagingData, _ := Packaging(&req) + packagingData, err := Packaging(&req) + if err != nil { + t.Fatalf("unexpected err: %v", err) + } if !tt.exists { if len(packagingData.Packages) != 0 { diff --git a/checks/raw/maintained_test.go b/checks/raw/maintained_test.go index 2df1ef7dd6f..2117175653a 100644 --- a/checks/raw/maintained_test.go +++ b/checks/raw/maintained_test.go @@ -78,7 +78,7 @@ func TestMaintained(t *testing.T) { }) t.Run("returns error if IsArchived fails", func(t *testing.T) { - mockRepoClient.EXPECT().IsArchived().Return(false, fmt.Errorf("some error")) //nolint:goerr113 + mockRepoClient.EXPECT().IsArchived().Return(false, fmt.Errorf("some error")) _, err := Maintained(req) if err == nil { @@ -88,7 +88,7 @@ func TestMaintained(t *testing.T) { t.Run("returns error if ListCommits fails", func(t *testing.T) { mockRepoClient.EXPECT().IsArchived().Return(false, nil) - mockRepoClient.EXPECT().ListCommits().Return(nil, fmt.Errorf("some error")) //nolint:goerr113 + mockRepoClient.EXPECT().ListCommits().Return(nil, fmt.Errorf("some error")) _, err := Maintained(req) if err == nil { @@ -99,7 +99,7 @@ func TestMaintained(t *testing.T) { t.Run("returns error if ListIssues fails", func(t *testing.T) { mockRepoClient.EXPECT().IsArchived().Return(false, nil) mockRepoClient.EXPECT().ListCommits().Return([]clients.Commit{}, nil) - mockRepoClient.EXPECT().ListIssues().Return(nil, fmt.Errorf("some error")) //nolint:goerr113 + mockRepoClient.EXPECT().ListIssues().Return(nil, fmt.Errorf("some error")) _, err := Maintained(req) if err == nil { @@ -111,7 +111,7 @@ func TestMaintained(t *testing.T) { mockRepoClient.EXPECT().IsArchived().Return(false, nil) mockRepoClient.EXPECT().ListCommits().Return([]clients.Commit{}, nil) mockRepoClient.EXPECT().ListIssues().Return([]clients.Issue{}, nil) - mockRepoClient.EXPECT().GetCreatedAt().Return(time.Time{}, fmt.Errorf("some error")) //nolint:goerr113 + mockRepoClient.EXPECT().GetCreatedAt().Return(time.Time{}, fmt.Errorf("some error")) _, err := Maintained(req) if err == nil { diff --git a/checks/raw/pinned_dependencies_test.go b/checks/raw/pinned_dependencies_test.go index 3800006d9c0..0eb2ea67c14 100644 --- a/checks/raw/pinned_dependencies_test.go +++ b/checks/raw/pinned_dependencies_test.go @@ -159,14 +159,12 @@ func TestGithubWorkflowPinningPattern(t *testing.T) { ispinned: true, }, { - desc: "non-github docker image pinned by digest", - //nolint:lll + desc: "non-github docker image pinned by digest", uses: "docker://gcr.io/distroless/static-debian11@sha256:9e6f8952f12974d088f648ed6252ea1887cdd8641719c8acd36bf6d2537e71c0", ispinned: true, }, { - desc: "non-github docker image pinned to mutable tag", - //nolint:lll + desc: "non-github docker image pinned to mutable tag", uses: "docker://gcr.io/distroless/static-debian11:sha256-3876708467ad6f38f263774aa107d331e8de6558a2874aa223b96fc0d9dfc820.sig", ispinned: false, }, @@ -635,7 +633,7 @@ func TestDockerfileInvalidFiles(t *testing.T) { func TestDockerfileInsecureDownloadsLineNumber(t *testing.T) { t.Parallel() - //nolint:govet,lll + //nolint:govet tests := []struct { name string filename string @@ -847,7 +845,7 @@ func TestDockerfileInsecureDownloadsLineNumber(t *testing.T) { func TestShellscriptInsecureDownloadsLineNumber(t *testing.T) { t.Parallel() - //nolint:govet,lll + //nolint:govet tests := []struct { name string filename string diff --git a/checks/raw/vulnerabilities_test.go b/checks/raw/vulnerabilities_test.go index 76da2f3514c..0df35e35557 100644 --- a/checks/raw/vulnerabilities_test.go +++ b/checks/raw/vulnerabilities_test.go @@ -47,9 +47,8 @@ func TestVulnerabilities(t *testing.T) { numberofCommits: 1, }, { - name: "err response", - wantErr: true, - //nolint:goerr113 + name: "err response", + wantErr: true, err: errors.New("error"), vulnsResponse: clients.VulnerabilitiesResponse{}, }, @@ -93,7 +92,6 @@ func TestVulnerabilities(t *testing.T) { mockVulnClient.EXPECT().ListUnfixedVulnerabilities(context.TODO(), gomock.Any(), gomock.Any()).DoAndReturn( func(ctx context.Context, commit string, localPath string) (clients.VulnerabilitiesResponse, error) { if tt.vulnsError { - //nolint:goerr113 return clients.VulnerabilitiesResponse{}, errors.New("error") } return tt.vulnsResponse, tt.err diff --git a/checks/sast_test.go b/checks/sast_test.go index 1f296fcdc13..05d95f1d94b 100644 --- a/checks/sast_test.go +++ b/checks/sast_test.go @@ -34,7 +34,7 @@ import ( func Test_SAST(t *testing.T) { t.Parallel() - //nolint:govet,goerr113 + //nolint:govet tests := []struct { name string err error diff --git a/checks/signed_releases_test.go b/checks/signed_releases_test.go index cfdaeaca355..39bdc017fb7 100644 --- a/checks/signed_releases_test.go +++ b/checks/signed_releases_test.go @@ -364,10 +364,10 @@ func TestSignedRelease(t *testing.T) { { name: "Error getting releases", - err: errors.New("Error getting releases"), //nolint:goerr113 + err: errors.New("Error getting releases"), expected: checker.CheckResult{ Score: -1, - Error: errors.New("Error getting releases"), //nolint:goerr113 + Error: errors.New("Error getting releases"), }, }, } diff --git a/clients/git/client_test.go b/clients/git/client_test.go index ce2d175fc34..483bad5977c 100644 --- a/clients/git/client_test.go +++ b/clients/git/client_test.go @@ -50,7 +50,7 @@ func createTestRepo(t *testing.T) (path string) { // Create a new file filePath := filepath.Join(dir, "file") - err = os.WriteFile(filePath, []byte("Hello, World!"), 0o644) //nolint:gosec + err = os.WriteFile(filePath, []byte("Hello, World!"), 0o600) if err != nil { t.Fatalf("Failed to write a file: %v", err) } @@ -185,7 +185,7 @@ func TestSearch(t *testing.T) { // Use the same test repo for all test cases. repoPath := createTestRepo(t) filePath := filepath.Join(repoPath, "test.txt") - err := os.WriteFile(filePath, []byte("Hello, World!"), 0o644) //nolint:gosec + err := os.WriteFile(filePath, []byte("Hello, World!"), 0o600) if err != nil { t.Fatalf("WriteFile() failed: %v", err) } diff --git a/clients/githubrepo/copy_test.go b/clients/githubrepo/copy_test.go index 73d3b8eacec..fe14f8c1aa9 100644 --- a/clients/githubrepo/copy_test.go +++ b/clients/githubrepo/copy_test.go @@ -53,7 +53,7 @@ func TestCopyBoolPtr(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() copyBoolPtr(tt.src, tt.dest) - if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && **tt.dest != *tt.want) { //nolint:lll + if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && **tt.dest != *tt.want) { t.Errorf("copyBoolPtr() got = %v, want %v", *tt.dest, tt.want) } }) @@ -103,7 +103,7 @@ func TestCopyInt32Ptr(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() copyInt32Ptr(tt.src, tt.dest) - if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && **tt.dest != *tt.want) { //nolint:lll + if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && **tt.dest != *tt.want) { t.Errorf("copyInt32Ptr() got = %v, want %v", *tt.dest, tt.want) } }) @@ -153,7 +153,7 @@ func TestCopyStringPtr(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() copyStringPtr(tt.src, tt.dest) - if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && **tt.dest != *tt.want) { //nolint:lll + if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && **tt.dest != *tt.want) { t.Errorf("copyStringPtr() got = %v, want %v", *tt.dest, tt.want) } }) @@ -201,7 +201,7 @@ func TestCopyTimePtr(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() copyTimePtr(tt.src, tt.dest) - if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && !(*tt.dest).Equal(*tt.want)) { //nolint:lll + if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && !(*tt.dest).Equal(*tt.want)) { t.Errorf("copyTimePtr() got = %v, want %v", *tt.dest, tt.want) } }) @@ -283,7 +283,7 @@ func TestCopyRepoAssociationPtr(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() copyRepoAssociationPtr(tt.src, tt.dest) - if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && !reflect.DeepEqual(**tt.dest, *tt.want)) { //nolint:lll + if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && !reflect.DeepEqual(**tt.dest, *tt.want)) { t.Errorf("copyRepoAssociationPtr() got = %v, want %v", *tt.dest, tt.want) } }) diff --git a/clients/githubrepo/roundtripper/tokens/accessor_test.go b/clients/githubrepo/roundtripper/tokens/accessor_test.go index 1736eb5a4d7..129b959cbb4 100644 --- a/clients/githubrepo/roundtripper/tokens/accessor_test.go +++ b/clients/githubrepo/roundtripper/tokens/accessor_test.go @@ -85,15 +85,9 @@ func testServer(t *testing.T) { serverURL := strings.TrimPrefix(server.URL, "http://") t.Setenv("GITHUB_AUTH_SERVER", serverURL) t.Cleanup(server.Close) - myRPCService := &MyRPCService{} - rpc.Register(myRPCService) //nolint:errcheck rpc.HandleHTTP() got := MakeTokenAccessor() if got == nil { t.Errorf("MakeTokenAccessor() = nil, want not nil") } } - -type MyRPCService struct { - // Define your RPC service methods here -} diff --git a/clients/githubrepo/webhook_test.go b/clients/githubrepo/webhook_test.go index 15829c77281..97eae7ab03d 100644 --- a/clients/githubrepo/webhook_test.go +++ b/clients/githubrepo/webhook_test.go @@ -33,7 +33,6 @@ type stubTripper struct { func (s stubTripper) RoundTrip(_ *http.Request) (*http.Response, error) { f, err := os.Open(s.responsePath) if err != nil { - //nolint:wrapcheck return nil, err } return &http.Response{ diff --git a/clients/gitlabrepo/branches_test.go b/clients/gitlabrepo/branches_test.go index 9f5f2eb5aea..10269e1814c 100644 --- a/clients/gitlabrepo/branches_test.go +++ b/clients/gitlabrepo/branches_test.go @@ -110,11 +110,12 @@ func TestGetBranches(t *testing.T) { handler.once.Do(func() {}) - //nolint:errcheck - br, _ := handler.getBranch(tt.branchName) + br, err := handler.getBranch(tt.branchName) + if err != nil { + t.Fatalf("unexpected err: %v", err) + } - //nolint:unconvert - if string(*br.Name) != tt.expectedBranchName { + if *br.Name != tt.expectedBranchName { t.Errorf("Branch Name (%s) didn't match expected value (%s)", *br.Name, tt.expectedBranchName) } diff --git a/clients/gitlabrepo/issues_test.go b/clients/gitlabrepo/issues_test.go index f61ee63fb0d..32a5a2d41cd 100644 --- a/clients/gitlabrepo/issues_test.go +++ b/clients/gitlabrepo/issues_test.go @@ -40,7 +40,6 @@ func (s suffixStubTripper) RoundTrip(r *http.Request) (*http.Response, error) { suffix := pathParts[len(pathParts)-1] f, err := os.Open(s.responsePaths[suffix]) if err != nil { - //nolint:wrapcheck return nil, err } return &http.Response{ diff --git a/clients/gitlabrepo/webhook_test.go b/clients/gitlabrepo/webhook_test.go index bc69cea2c5b..01093de39bf 100644 --- a/clients/gitlabrepo/webhook_test.go +++ b/clients/gitlabrepo/webhook_test.go @@ -32,7 +32,6 @@ type stubTripper struct { func (s stubTripper) RoundTrip(_ *http.Request) (*http.Response, error) { f, err := os.Open(s.responsePath) if err != nil { - //nolint:wrapcheck return nil, err } return &http.Response{ diff --git a/cmd/internal/nuget/client_test.go b/cmd/internal/nuget/client_test.go index de369fdd3f9..350386d42f6 100644 --- a/cmd/internal/nuget/client_test.go +++ b/cmd/internal/nuget/client_test.go @@ -390,7 +390,6 @@ func Test_fetchGitRepositoryFromNuget(t *testing.T) { resultPackageRegistrationPages: []resultPackagePage{}, resultPackageSpec: "", }, - //nolint:lll want: "internal error: failed to parse nuget package registration index json: invalid character 'e' in literal true (expecting 'r')", wantErr: true, }, @@ -443,7 +442,6 @@ func Test_fetchGitRepositoryFromNuget(t *testing.T) { }, resultPackageSpec: "", }, - //nolint:lll want: "internal error: failed to parse nuget package registration page: invalid character 'e' in literal true (expecting 'r')", wantErr: true, }, @@ -514,7 +512,6 @@ func Test_fetchGitRepositoryFromNuget(t *testing.T) { resultPackageSpec: "", version: "", }, - //nolint:lll want: "internal error: failed to parse nuget package registration index json: failed to unmarshal json: json: cannot unmarshal number into Go struct field Alias.listed of type bool", wantErr: true, }, @@ -580,7 +577,6 @@ func nugetIndexOrPageTestResults(url string, test *nugetTest) (*http.Response, e urlResponseIndex := slices.IndexFunc(test.args.resultPackageRegistrationPages, func(page resultPackagePage) bool { return page.url == url }) if urlResponseIndex == -1 { - //nolint:goerr113 return nil, errors.New("error") } page := test.args.resultPackageRegistrationPages[urlResponseIndex] @@ -597,13 +593,11 @@ func nugetPackageIndexAndSpecResponse(t *testing.T, url string, test *nugetTest) } t.Errorf("fetchGitRepositoryFromNuget() version = %v, expected version = %v", url, test.args.version) } - //nolint:goerr113 return nil, errors.New("error") } func testResult(wantErr bool, responseFileName string) (*http.Response, error) { if wantErr && responseFileName == "" { - //nolint:goerr113 return nil, errors.New("error") } if wantErr && responseFileName == "text" { diff --git a/cmd/internal/scdiff/app/compare_test.go b/cmd/internal/scdiff/app/compare_test.go index 8b8da9dfef5..f4bfc5b3816 100644 --- a/cmd/internal/scdiff/app/compare_test.go +++ b/cmd/internal/scdiff/app/compare_test.go @@ -21,7 +21,6 @@ import ( "testing" ) -//nolint:lll // results are long func Test_compare(t *testing.T) { t.Parallel() //nolint:govet // struct alignment @@ -97,7 +96,6 @@ func (a alwaysErrorReader) Read(b []byte) (n int, err error) { return 0, io.ErrClosedPipe } -//nolint:lll // results are long func Test_compare_reader_err(t *testing.T) { t.Parallel() //nolint:govet // struct alignment diff --git a/cmd/internal/scdiff/app/generate_test.go b/cmd/internal/scdiff/app/generate_test.go index fd7f142e10a..f8dbb79fc80 100644 --- a/cmd/internal/scdiff/app/generate_test.go +++ b/cmd/internal/scdiff/app/generate_test.go @@ -31,7 +31,6 @@ type resultCounter struct { lines int } -//nolint:wrapcheck func (rc *resultCounter) Write(p []byte) (n int, err error) { rc.lines += bytes.Count(p, []byte("\n")) return rc.b.Write(p) diff --git a/cmd/package_managers_test.go b/cmd/package_managers_test.go index 8b70eac8fc7..a8ba8ec1e97 100644 --- a/cmd/package_managers_test.go +++ b/cmd/package_managers_test.go @@ -141,7 +141,6 @@ func Test_fetchGitRepositoryFromNPM(t *testing.T) { p.EXPECT().Get(gomock.Any(), tt.args.packageName). DoAndReturn(func(url, packageName string) (*http.Response, error) { if tt.wantErr && tt.args.result == "" { - //nolint:goerr113 return nil, errors.New("error") } @@ -316,7 +315,6 @@ func Test_fetchGitRepositoryFromPYPI(t *testing.T) { name: "fetchGitRepositoryFromPYPI", args: args{ packageName: "some-package", - //nolint:lll result: ` { "info": { @@ -450,7 +448,6 @@ func Test_fetchGitRepositoryFromPYPI(t *testing.T) { p.EXPECT().Get(gomock.Any(), tt.args.packageName). DoAndReturn(func(url, packageName string) (*http.Response, error) { if tt.wantErr && tt.args.result == "" { - //nolint:goerr113 return nil, errors.New("error") } @@ -487,7 +484,6 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) { name: "fetchGitRepositoryFromPYPI", args: args{ packageName: "npm-package", - //nolint:lll result: ` { "name": "color", @@ -609,7 +605,6 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) { name: "empty project url", args: args{ packageName: "npm-package", - //nolint:lll result: ` { "name": "color", @@ -717,7 +712,6 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) { p.EXPECT().Get(gomock.Any(), tt.args.packageName). DoAndReturn(func(url, packageName string) (*http.Response, error) { if tt.wantErr && tt.args.result == "" { - //nolint:goerr113 return nil, errors.New("error") } @@ -778,7 +772,6 @@ func Test_fetchGitRepositoryFromNuget(t *testing.T) { n.EXPECT().GitRepositoryByPackageName(tt.args.packageName). DoAndReturn(func(packageName string) (string, error) { if tt.wantErr && tt.args.result == "" { - //nolint:goerr113 return "", errors.New("error") } diff --git a/cron/config/config_test.go b/cron/config/config_test.go index c1356a3a754..6fe09b22a7d 100644 --- a/cron/config/config_test.go +++ b/cron/config/config_test.go @@ -70,7 +70,6 @@ func getByteValueFromFile(filename string) ([]byte, error) { if filename == "" { return nil, nil } - //nolint:wrapcheck return os.ReadFile(filename) } diff --git a/cron/internal/pubsub/publisher_test.go b/cron/internal/pubsub/publisher_test.go index 0860e77c71f..524e95c7503 100644 --- a/cron/internal/pubsub/publisher_test.go +++ b/cron/internal/pubsub/publisher_test.go @@ -33,7 +33,6 @@ func (topic *mockSucceedTopic) Send(ctx context.Context, msg *pubsub.Message) er type mockFailTopic struct{} func (topic *mockFailTopic) Send(ctx context.Context, msg *pubsub.Message) error { - //nolint:goerr113 return fmt.Errorf("mockFailTopic failed to send") } diff --git a/cron/internal/pubsub/subscriber_gocloud_test.go b/cron/internal/pubsub/subscriber_gocloud_test.go index 791b8d77874..621349ace35 100644 --- a/cron/internal/pubsub/subscriber_gocloud_test.go +++ b/cron/internal/pubsub/subscriber_gocloud_test.go @@ -65,8 +65,7 @@ func TestSubscriber(t *testing.T) { { name: "ReceiveFails", hasErrOnReceive: true, - //nolint:goerr113 - errOnReceive: errors.New("mock Receive failure"), + errOnReceive: errors.New("mock Receive failure"), }, { name: "ShutdownFails", @@ -78,8 +77,7 @@ func TestSubscriber(t *testing.T) { }, }, hasErrOnShutdown: true, - //nolint:goerr113 - errOnShutdown: errors.New("mock Shutdown close"), + errOnShutdown: errors.New("mock Shutdown close"), }, } for _, testcase := range testcases { diff --git a/e2e/attestor_policy_test.go b/e2e/attestor_policy_test.go index 9fe2c7b7ed2..218e5998dae 100644 --- a/e2e/attestor_policy_test.go +++ b/e2e/attestor_policy_test.go @@ -247,6 +247,6 @@ func getScorecardResult(repoURL string) (pkg.ScorecardResult, error) { if err != nil { return pkg.ScorecardResult{}, fmt.Errorf("couldn't set up clients: %w", err) } - //nolint:wrapcheck,lll + return pkg.RunScorecard(ctx, repo, clients.HeadSHA, 0, enabledChecks, repoClient, ossFuzzRepoClient, ciiClient, vulnsClient) } diff --git a/errors/internal_test.go b/errors/internal_test.go index c8a077b7f1c..b1ea3b74a69 100644 --- a/errors/internal_test.go +++ b/errors/internal_test.go @@ -32,10 +32,10 @@ func TestCreateInternal(t *testing.T) { }{ name: "non-nil error and non-empty message", args: args{ - e: errors.New("test error"), //nolint:goerr113 + e: errors.New("test error"), msg: "test message", }, - want: fmt.Errorf("test error: test message"), //nolint:goerr113 + want: fmt.Errorf("test error: test message"), } t.Run(test.name, func(t *testing.T) { diff --git a/errors/public_test.go b/errors/public_test.go index 70339ea0123..16a8c0b56c1 100644 --- a/errors/public_test.go +++ b/errors/public_test.go @@ -92,7 +92,7 @@ func TestGetName(t *testing.T) { { name: "unknown error", args: args{ - err: errors.New("unknown error"), //nolint:goerr113 + err: errors.New("unknown error"), }, want: "ErrUnknown", }, diff --git a/options/flags_test.go b/options/flags_test.go index 4dbd6f5c6b4..21d88404255 100644 --- a/options/flags_test.go +++ b/options/flags_test.go @@ -175,7 +175,7 @@ func TestOptions_AddFlags_Format(t *testing.T) { cmd := &cobra.Command{} tt.opts.AddFlags(cmd) if !cmp.Equal(cmd.Flag(FlagFormat).Value.String(), strings.Join(tt.expected, ", ")) { - t.Errorf("expected FlagFormat to be %q, but got %q", strings.Join(tt.expected, ", "), cmd.Flag(FlagFormat).Value.String()) //nolint:lll + t.Errorf("expected FlagFormat to be %q, but got %q", strings.Join(tt.expected, ", "), cmd.Flag(FlagFormat).Value.String()) } }) } diff --git a/pkg/json_raw_results_test.go b/pkg/json_raw_results_test.go index 82adcc8b116..7b489c324d0 100644 --- a/pkg/json_raw_results_test.go +++ b/pkg/json_raw_results_test.go @@ -583,7 +583,7 @@ func TestJsonScorecardRawResult_AddOssfBestPracticesRawResults(t *testing.T) { t.Errorf("addOssfBestPracticesRawResults() error = %v, wantError %v", err, test.wantError) } if r.Results.OssfBestPractices.Badge != test.input.Badge.String() { - t.Errorf("addOssfBestPracticesRawResults() badge = %v, want %v", r.Results.OssfBestPractices.Badge, test.input.Badge.String()) //nolint:lll + t.Errorf("addOssfBestPracticesRawResults() badge = %v, want %v", r.Results.OssfBestPractices.Badge, test.input.Badge.String()) } }) } @@ -650,7 +650,7 @@ func TestJsonScorecardRawResult_AddCodeReviewRawResults(t *testing.T) { t.Errorf("addCodeReviewRawResults() error = %v, wantError %v", err, test.wantError) } if len(r.Results.DefaultBranchChangesets) != len(test.input.DefaultBranchChangesets) { - t.Errorf("addCodeReviewRawResults() changesets length = %v, want %v", len(r.Results.DefaultBranchChangesets), len(test.input.DefaultBranchChangesets)) //nolint:lll + t.Errorf("addCodeReviewRawResults() changesets length = %v, want %v", len(r.Results.DefaultBranchChangesets), len(test.input.DefaultBranchChangesets)) } }) } @@ -724,7 +724,7 @@ func TestAddCodeReviewRawResults(t *testing.T) { } if !reflect.DeepEqual(r.Results.DefaultBranchChangesets, expected) { - t.Errorf("addCodeReviewRawResults did not produce the expected output. Got: %v, Expected: %v", r.Results.DefaultBranchChangesets, expected) //nolint:lll + t.Errorf("addCodeReviewRawResults did not produce the expected output. Got: %v, Expected: %v", r.Results.DefaultBranchChangesets, expected) } } @@ -820,12 +820,12 @@ func TestAddBinaryArtifactRawResults(t *testing.T) { } if len(r.Results.Binaries) != len(expected) { - t.Errorf("addBinaryArtifactRawResults did not add the correct number of files. Expected %d, got %d", len(expected), len(r.Results.Binaries)) //nolint:lll + t.Errorf("addBinaryArtifactRawResults did not add the correct number of files. Expected %d, got %d", len(expected), len(r.Results.Binaries)) } for i, file := range r.Results.Binaries { if file.Path != expected[i].Path { - t.Errorf("addBinaryArtifactRawResults did not add the correct file. Expected %s, got %s", expected[i].Path, file.Path) //nolint:lll + t.Errorf("addBinaryArtifactRawResults did not add the correct file. Expected %s, got %s", expected[i].Path, file.Path) } } } @@ -892,25 +892,25 @@ func TestAddSecurityPolicyRawResults(t *testing.T) { } if len(r.Results.SecurityPolicies) != len(expected) { - t.Errorf("addSecurityPolicyRawResults did not add the correct number of policies. Expected %d, got %d", len(expected), len(r.Results.SecurityPolicies)) //nolint:lll + t.Errorf("addSecurityPolicyRawResults did not add the correct number of policies. Expected %d, got %d", len(expected), len(r.Results.SecurityPolicies)) } for i, policy := range r.Results.SecurityPolicies { if policy.Path != expected[i].Path { - t.Errorf("addSecurityPolicyRawResults did not add the correct policy. Expected %s, got %s", expected[i].Path, policy.Path) //nolint:lll + t.Errorf("addSecurityPolicyRawResults did not add the correct policy. Expected %s, got %s", expected[i].Path, policy.Path) } if policy.ContentLength != expected[i].ContentLength { - t.Errorf("addSecurityPolicyRawResults did not add the correct content length. Expected %d, got %d", expected[i].ContentLength, policy.ContentLength) //nolint:lll + t.Errorf("addSecurityPolicyRawResults did not add the correct content length. Expected %d, got %d", expected[i].ContentLength, policy.ContentLength) } if len(policy.Hits) != len(expected[i].Hits) { - t.Errorf("addSecurityPolicyRawResults did not add the correct number of hits. Expected %d, got %d", len(expected[i].Hits), len(policy.Hits)) //nolint:lll + t.Errorf("addSecurityPolicyRawResults did not add the correct number of hits. Expected %d, got %d", len(expected[i].Hits), len(policy.Hits)) } for j, hit := range policy.Hits { if hit.Type != expected[i].Hits[j].Type { - t.Errorf("addSecurityPolicyRawResults did not add the correct hit type. Expected %s, got %s", expected[i].Hits[j].Type, hit.Type) //nolint:lll + t.Errorf("addSecurityPolicyRawResults did not add the correct hit type. Expected %s, got %s", expected[i].Hits[j].Type, hit.Type) } } } @@ -944,12 +944,12 @@ func TestAddVulnerabilitiesRawResults(t *testing.T) { } if len(r.Results.DatabaseVulnerabilities) != len(expected) { - t.Errorf("addVulnerbilitiesRawResults did not add the correct number of vulnerabilities. Expected %d, got %d", len(expected), len(r.Results.DatabaseVulnerabilities)) //nolint:lll + t.Errorf("addVulnerbilitiesRawResults did not add the correct number of vulnerabilities. Expected %d, got %d", len(expected), len(r.Results.DatabaseVulnerabilities)) } for i, vuln := range r.Results.DatabaseVulnerabilities { if vuln.ID != expected[i].ID { - t.Errorf("addVulnerbilitiesRawResults did not add the correct vulnerability. Expected %s, got %s", expected[i].ID, vuln.ID) //nolint:lll + t.Errorf("addVulnerbilitiesRawResults did not add the correct vulnerability. Expected %s, got %s", expected[i].ID, vuln.ID) } } } @@ -1016,24 +1016,24 @@ func TestAddFuzzingRawResults(t *testing.T) { } if len(r.Results.Fuzzers) != len(expectedFuzzers) { - t.Errorf("addFuzzingRawResults did not add the correct number of fuzzers. Expected %d, got %d", len(expectedFuzzers), len(r.Results.Fuzzers)) //nolint:lll + t.Errorf("addFuzzingRawResults did not add the correct number of fuzzers. Expected %d, got %d", len(expectedFuzzers), len(r.Results.Fuzzers)) } for i, fuzzer := range r.Results.Fuzzers { if fuzzer.Name != expectedFuzzers[i].Name { - t.Errorf("addFuzzingRawResults did not add the correct fuzzer name. Expected %s, got %s", expectedFuzzers[i].Name, fuzzer.Name) //nolint:lll + t.Errorf("addFuzzingRawResults did not add the correct fuzzer name. Expected %s, got %s", expectedFuzzers[i].Name, fuzzer.Name) } if *fuzzer.URL != *expectedFuzzers[i].URL { - t.Errorf("addFuzzingRawResults did not add the correct fuzzer URL. Expected %s, got %s", *expectedFuzzers[i].URL, *fuzzer.URL) //nolint:lll + t.Errorf("addFuzzingRawResults did not add the correct fuzzer URL. Expected %s, got %s", *expectedFuzzers[i].URL, *fuzzer.URL) } if *fuzzer.Desc != *expectedFuzzers[i].Desc { - t.Errorf("addFuzzingRawResults did not add the correct fuzzer description. Expected %s, got %s", *expectedFuzzers[i].Desc, *fuzzer.Desc) //nolint:lll + t.Errorf("addFuzzingRawResults did not add the correct fuzzer description. Expected %s, got %s", *expectedFuzzers[i].Desc, *fuzzer.Desc) } if len(fuzzer.Files) != len(expectedFuzzers[i].Files) { - t.Errorf("addFuzzingRawResults did not add the correct number of files for fuzzer %s. Expected %d, got %d", fuzzer.Name, len(expectedFuzzers[i].Files), len(fuzzer.Files)) //nolint:lll + t.Errorf("addFuzzingRawResults did not add the correct number of files for fuzzer %s. Expected %d, got %d", fuzzer.Name, len(expectedFuzzers[i].Files), len(fuzzer.Files)) } for j, file := range fuzzer.Files { if file.Path != expectedFuzzers[i].Files[j].Path { - t.Errorf("addFuzzingRawResults did not add the correct file path for fuzzer %s. Expected %s, got %s", fuzzer.Name, expectedFuzzers[i].Files[j].Path, file.Path) //nolint:lll + t.Errorf("addFuzzingRawResults did not add the correct file path for fuzzer %s. Expected %s, got %s", fuzzer.Name, expectedFuzzers[i].Files[j].Path, file.Path) } } } @@ -1137,7 +1137,7 @@ func TestJsonScorecardRawResult(t *testing.T) { {ID: "CVE-2021-5678"}, } if cmp.Diff(r.Results.DatabaseVulnerabilities, expectedVulnerabilities) != "" { - t.Errorf("addVulnerbilitiesRawResults did not produce the expected results %v", cmp.Diff(r.Results.DatabaseVulnerabilities, expectedVulnerabilities)) //nolint:lll + t.Errorf("addVulnerbilitiesRawResults did not produce the expected results %v", cmp.Diff(r.Results.DatabaseVulnerabilities, expectedVulnerabilities)) } // test addBinaryArtifactRawResults @@ -1173,7 +1173,7 @@ func TestJsonScorecardRawResult(t *testing.T) { }, } if cmp.Diff(expectedSecurityPolicies, r.Results.SecurityPolicies) != "" { - t.Errorf("addSecurityPolicyRawResults did not produce the expected results %v", cmp.Diff(expectedSecurityPolicies, r.Results.SecurityPolicies)) //nolint:lll + t.Errorf("addSecurityPolicyRawResults did not produce the expected results %v", cmp.Diff(expectedSecurityPolicies, r.Results.SecurityPolicies)) } // test addFuzzingRawResults @@ -1202,7 +1202,7 @@ func TestJsonScorecardRawResult(t *testing.T) { }, } if cmp.Diff(expectedFuzzers, r.Results.Fuzzers, cmpopts.IgnoreFields(jsonTool{}, "URL", "Desc")) != "" { - t.Errorf("addFuzzingRawResults did not produce the expected results %v", cmp.Diff(expectedFuzzers, r.Results.Fuzzers)) //nolint:lll + t.Errorf("addFuzzingRawResults did not produce the expected results %v", cmp.Diff(expectedFuzzers, r.Results.Fuzzers)) } // test addBranchProtectionRawResults @@ -1224,7 +1224,6 @@ func intPtr(i int32) *int32 { return &i } -//nolint:lll func TestScorecardResult_AsRawJSON(t *testing.T) { type fields struct { Repo RepoInfo @@ -1249,7 +1248,7 @@ func TestScorecardResult_AsRawJSON(t *testing.T) { }, }, wantWriter: `{"date":"0001-01-01","repo":{"name":"bar","commit":"1234567890123456789012345678901234567890"},"scorecard":{"version":"","commit":""},"metadata":null,"results":{"workflows":[],"permissions":{},"licenses":[],"issues":null,"openssfBestPracticesBadge":{"badge":"Unknown"},"databaseVulnerabilities":[],"binaries":[],"securityPolicies":[],"dependencyUpdateTools":[],"branchProtections":{"branches":[],"codeownersFiles":null},"Contributors":{"users":null},"defaultBranchChangesets":[],"archived":{"status":false},"createdAt":{"timestamp":"0001-01-01T00:00:00Z"},"fuzzers":[],"releases":[],"packages":[],"dependencyPinning":{"dependencies":null}}} -`, //nolint:lll +`, }, } for _, tt := range tests { diff --git a/pkg/json_test.go b/pkg/json_test.go index 7b39de2b251..7391cfb1efd 100644 --- a/pkg/json_test.go +++ b/pkg/json_test.go @@ -495,7 +495,7 @@ func TestJSONOutput(t *testing.T) { func TestExperimentalFromJSON2_time(t *testing.T) { t.Parallel() - //nolint:lll,govet // result strings are long + //nolint:govet tests := []struct { name string result string diff --git a/pkg/scorecard_e2e_test.go b/pkg/scorecard_e2e_test.go index 4e641e56e1c..921a205daf5 100644 --- a/pkg/scorecard_e2e_test.go +++ b/pkg/scorecard_e2e_test.go @@ -52,7 +52,7 @@ func countDetails(c []checker.CheckDetail) (debug, info, warn int) { return debug, info, warn } -//nolint:lll,gocritic // comparison was failing with pointer types +//nolint:gocritic // comparison was failing with pointer types func compareScorecardResults(a, b ScorecardResult) bool { if a.Repo != b.Repo { fmt.Fprintf(GinkgoWriter, "Unequal repo details in results: %v vs %v\n", a.Repo, b.Repo) diff --git a/probes/hasOSVVulnerabilities/impl_test.go b/probes/hasOSVVulnerabilities/impl_test.go index 46d64ecbe51..75a88a0be48 100644 --- a/probes/hasOSVVulnerabilities/impl_test.go +++ b/probes/hasOSVVulnerabilities/impl_test.go @@ -88,11 +88,9 @@ func Test_Run(t *testing.T) { Probe: "hasOSVVulnerabilities", Message: "Project is vulnerable to: foo", Remediation: &probe.Remediation{ - //nolint:lll Text: `Fix the foo by following information from https://osv.dev/foo. If the vulnerability is in a dependency, update the dependency to a non-vulnerable version. If no update is available, consider whether to remove the dependency. If you believe the vulnerability does not affect your project, the vulnerability can be ignored. To ignore, create an osv-scanner.toml file next to the dependency manifest (e.g. package-lock.json) and specify the ID to ignore and reason. Details on the structure of osv-scanner.toml can be found on OSV-Scanner repository.`, - //nolint:lll Markdown: `Fix the foo by following information from [OSV](https://osv.dev/foo). If the vulnerability is in a dependency, update the dependency to a non-vulnerable version. If no update is available, consider whether to remove the dependency. If you believe the vulnerability does not affect your project, the vulnerability can be ignored. To ignore, create an osv-scanner.toml ([example](https://github.com/google/osv.dev/blob/eb99b02ec8895fe5b87d1e76675ddad79a15f817/vulnfeeds/osv-scanner.toml)) file next to the dependency manifest (e.g. package-lock.json) and specify the ID to ignore and reason. Details on the structure of osv-scanner.toml can be found on [OSV-Scanner repository](https://github.com/google/osv-scanner#ignore-vulnerabilities-by-id).`, diff --git a/remediation/remediations_test.go b/remediation/remediations_test.go index dce119881d5..3ea529aad58 100644 --- a/remediation/remediations_test.go +++ b/remediation/remediations_test.go @@ -66,7 +66,6 @@ func (s stubDigester) Digest(name string) (string, error) { } hash, ok := m[name] if !ok { - //nolint:goerr113 return "", fmt.Errorf("no hash for image: %q", name) } return fmt.Sprintf("sha256:%s", hash), nil @@ -75,7 +74,7 @@ func (s stubDigester) Digest(name string) (string, error) { func TestCreateDockerfilePinningRemediation(t *testing.T) { t.Parallel() - //nolint:govet,lll + //nolint:govet tests := []struct { name string dep checker.Dependency