Skip to content

Commit

Permalink
🌱 enable nolintlint linter and fix violations (#3650)
Browse files Browse the repository at this point in the history
* enable nolintlint

Signed-off-by: Spencer Schrock <[email protected]>

* first chunk of fixing nolintlint

Signed-off-by: Spencer Schrock <[email protected]>

* second chunk of fixing nolintlint

Signed-off-by: Spencer Schrock <[email protected]>

* third chunk of fixing nolintlint

Signed-off-by: Spencer Schrock <[email protected]>

* fourth chunk of fixing nolintlint

Signed-off-by: Spencer Schrock <[email protected]>

* include reason for the specific linter config

Signed-off-by: Spencer Schrock <[email protected]>

* fifth chunk of fixing nolintlint

Signed-off-by: Spencer Schrock <[email protected]>

* fix linter errors that are somehow still triggering

Signed-off-by: Spencer Schrock <[email protected]>

---------

Signed-off-by: Spencer Schrock <[email protected]>
  • Loading branch information
spencerschrock authored Nov 15, 2023
1 parent 288319a commit 92470de
Show file tree
Hide file tree
Showing 158 changed files with 322 additions and 374 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ linters:
- misspell
- nakedret
- nestif
- nolintlint
- predeclared
- staticcheck
- stylecheck
Expand Down Expand Up @@ -152,6 +153,10 @@ linters-settings:
- ptrToRefParam
- typeUnparen
- unnecessaryBlock
nolintlint:
# `//nolint` should mention specific linter such as `//nolint:my-linter`
# Overly broad directives can hide unrelated issues
require-specific: true
wrapcheck:
ignorePackageGlobs:
- github.com/ossf/scorecard/v4/checks/fileparser
4 changes: 2 additions & 2 deletions attestor/policy/attestation_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestCheckPreventBinaryArtifacts(t *testing.T) {
func TestCheckCodeReviewed(t *testing.T) {
t.Parallel()

// nolint
//nolint:govet
tests := []struct {
err error
raw *checker.RawResults
Expand Down Expand Up @@ -385,7 +385,7 @@ func asPointer(s string) *string {
func TestNoUnpinnedDependencies(t *testing.T) {
t.Parallel()

// nolint
//nolint:govet
tests := []struct {
err error
raw *checker.RawResults
Expand Down
24 changes: 12 additions & 12 deletions checker/check_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestAggregateScores(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := AggregateScores(tt.args.scores...); got != tt.want { //nolint:govet
if got := AggregateScores(tt.args.scores...); got != tt.want {
t.Errorf("AggregateScores() = %v, want %v", got, tt.want)
}
})
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestAggregateScoresWithWeight(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := AggregateScoresWithWeight(tt.args.scores); got != tt.want { //nolint:govet
if got := AggregateScoresWithWeight(tt.args.scores); got != tt.want {
t.Errorf("AggregateScoresWithWeight() = %v, want %v", got, tt.want)
}
})
Expand Down Expand Up @@ -132,8 +132,8 @@ func TestCreateProportionalScore(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := CreateProportionalScore(tt.args.success, tt.args.total); got != tt.want { //nolint:govet
t.Errorf("CreateProportionalScore() = %v, want %v", got, tt.want) //nolint:govet
if got := CreateProportionalScore(tt.args.success, tt.args.total); got != tt.want {
t.Errorf("CreateProportionalScore() = %v, want %v", got, tt.want)
}
})
}
Expand Down Expand Up @@ -438,8 +438,8 @@ func TestNormalizeReason(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := NormalizeReason(tt.args.reason, tt.args.score); got != tt.want { //nolint:govet
t.Errorf("NormalizeReason() = %v, want %v", got, tt.want) //nolint:govet
if got := NormalizeReason(tt.args.reason, tt.args.score); got != tt.want {
t.Errorf("NormalizeReason() = %v, want %v", got, tt.want)
}
})
}
Expand Down Expand Up @@ -490,8 +490,8 @@ func TestCreateResultWithScore(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := CreateResultWithScore(tt.args.name, tt.args.reason, tt.args.score); !cmp.Equal(got, tt.want) { //nolint:lll,govet
t.Errorf("CreateResultWithScore() = %v, want %v", got, cmp.Diff(got, tt.want)) //nolint:govet
if got := CreateResultWithScore(tt.args.name, tt.args.reason, tt.args.score); !cmp.Equal(got, tt.want) {
t.Errorf("CreateResultWithScore() = %v, want %v", got, cmp.Diff(got, tt.want))
}
})
}
Expand Down Expand Up @@ -545,8 +545,8 @@ 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:govet,lll
t.Errorf("CreateProportionalScoreResult() = %v, want %v", got, cmp.Diff(got, tt.want)) //nolint:govet
if got := CreateProportionalScoreResult(tt.args.name, tt.args.reason, tt.args.b, tt.args.t); !cmp.Equal(got, tt.want) { //nolint:lll
t.Errorf("CreateProportionalScoreResult() = %v, want %v", got, cmp.Diff(got, tt.want))
}
})
}
Expand Down Expand Up @@ -594,7 +594,7 @@ func TestCreateMaxScoreResult(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := CreateMaxScoreResult(tt.args.name, tt.args.reason); !cmp.Equal(got, tt.want) { //nolint:govet
if got := CreateMaxScoreResult(tt.args.name, tt.args.reason); !cmp.Equal(got, tt.want) {
t.Errorf("CreateMaxScoreResult() = %v, want %v", got, cmp.Diff(got, tt.want))
}
})
Expand Down Expand Up @@ -643,7 +643,7 @@ func TestCreateMinScoreResult(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := CreateMinScoreResult(tt.args.name, tt.args.reason); !cmp.Equal(got, tt.want) { //nolint:govet
if got := CreateMinScoreResult(tt.args.name, tt.args.reason); !cmp.Equal(got, tt.want) {
t.Errorf("CreateMinScoreResult() = %v, want %v", got, cmp.Diff(got, tt.want))
}
})
Expand Down
5 changes: 2 additions & 3 deletions checker/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import (
"github.com/ossf/scorecard/v4/log"
)

// nolint:paralleltest
// because we are using t.Setenv.
func TestGetClients(t *testing.T) { //nolint:gocognit
//nolint:paralleltest // because we are using t.Setenv.
func TestGetClients(t *testing.T) {
type args struct { //nolint:govet
ctx context.Context
repoURI string
Expand Down
4 changes: 2 additions & 2 deletions checker/raw_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (

// RawResults contains results before a policy
// is applied.
// nolint
//
//nolint:govet
type RawResults struct {
BinaryArtifactResults BinaryArtifactData
BranchProtectionResults BranchProtectionsData
Expand Down Expand Up @@ -77,7 +78,6 @@ type PackagingData struct {
}

// Package represents a package.
// nolint
type Package struct {
// TODO: not supported yet. This needs to be unique across
// ecosystems: purl, OSV, CPE, etc.
Expand Down
4 changes: 2 additions & 2 deletions checks/all_checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (

func Test_registerCheck(t *testing.T) {
t.Parallel()
//nolint
//nolint:govet
type args struct {
name string
fn checker.CheckFn
}
//nolint
//nolint:govet
tests := []struct {
name string
args args
Expand Down
3 changes: 1 addition & 2 deletions checks/branch_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {

rel1 := "release/v.1"
sha := "8fb3cb86082b17144a80402f5367ae65f06083bd"
//nolint:goconst
main := "main"
trueVal := true
falseVal := false
var zeroVal int32

var oneVal int32 = 1

//nolint
//nolint:govet
tests := []struct {
name string
expected scut.TestReturn
Expand Down
3 changes: 1 addition & 2 deletions checks/code_review_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ import (
// TestCodeReview tests the code review checker.
func TestCodereview(t *testing.T) {
t.Parallel()
//fieldalignment lint issue. Ignoring it as it is not important for this test.
//nolint
//nolint:goerr113
tests := []struct {
err error
name string
Expand Down
5 changes: 1 addition & 4 deletions checks/contributors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
// TestContributors tests the contributors check.
func TestContributors(t *testing.T) {
t.Parallel()
//fieldalignment lint issue. Ignoring it as it is not important for this test.
//nolint
tests := []struct {
err error
name string
Expand Down Expand Up @@ -61,7 +59,6 @@ func TestContributors(t *testing.T) {
name: "Valid contributors with enough contributors and companies",
contrib: []clients.User{
{

Companies: []string{"company1"},
NumContributions: 10,
Organizations: []clients.User{
Expand Down Expand Up @@ -146,7 +143,7 @@ func TestContributors(t *testing.T) {
},
},
{
err: errors.New("error"),
err: errors.New("error"), //nolint:goerr113
name: "Error getting contributors",
contrib: []clients.User{},
expected: checker.CheckResult{
Expand Down
2 changes: 1 addition & 1 deletion checks/dependency_update_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// CheckDependencyUpdateTool is the exported name for Automatic-Depdendency-Update.
const CheckDependencyUpdateTool = "Dependency-Update-Tool"

// nolint
//nolint:gochecknoinits
func init() {
supportedRequestTypes := []checker.RequestType{
checker.FileBased,
Expand Down
2 changes: 1 addition & 1 deletion checks/dependency_update_tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
// TestDependencyUpdateTool tests the DependencyUpdateTool checker.
func TestDependencyUpdateTool(t *testing.T) {
t.Parallel()
//nolint
//nolint:govet
tests := []struct {
name string
wantErr bool
Expand Down
2 changes: 1 addition & 1 deletion checks/evaluation/binary_artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// TestBinaryArtifacts tests the binary artifacts check.
func TestBinaryArtifacts(t *testing.T) {
t.Parallel()
//nolint
//nolint:govet
type args struct {
name string
dl checker.DetailLogger
Expand Down
18 changes: 8 additions & 10 deletions checks/evaluation/ci_tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ func Test_isTest(t *testing.T) {
func Test_prHasSuccessfulCheck(t *testing.T) {
t.Parallel()

//enabled nolint because this is a test
//nolint
tests := []struct {
name string
args checker.RevisionCIInfo
Expand Down Expand Up @@ -263,13 +261,13 @@ func Test_prHasSuccessStatus(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := prHasSuccessStatus(tt.args.r, tt.args.dl) //nolint:govet
if (err != nil) != tt.wantErr { //nolint:govet
t.Errorf("prHasSuccessStatus() error = %v, wantErr %v", err, tt.wantErr) //nolint:govet
got, err := prHasSuccessStatus(tt.args.r, tt.args.dl)
if (err != nil) != tt.wantErr {
t.Errorf("prHasSuccessStatus() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want { //nolint:govet
t.Errorf("prHasSuccessStatus() got = %v, want %v", got, tt.want) //nolint:govet
if got != tt.want {
t.Errorf("prHasSuccessStatus() got = %v, want %v", got, tt.want)
}
})
}
Expand Down Expand Up @@ -360,7 +358,7 @@ func Test_prHasSuccessfulCheckAdditional(t *testing.T) {
t.Errorf("prHasSuccessfulCheck() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want { //nolint:govet
if got != tt.want {
t.Errorf("prHasSuccessfulCheck() got = %v, want %v", got, tt.want)
}
})
Expand Down Expand Up @@ -449,8 +447,8 @@ func TestCITests(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := CITests(tt.args.in0, tt.args.c, tt.args.dl); got.Score != tt.want { //nolint:govet
t.Errorf("CITests() = %v, want %v", got.Score, tt.want) //nolint:govet
if got := CITests(tt.args.in0, tt.args.c, tt.args.dl); got.Score != tt.want {
t.Errorf("CITests() = %v, want %v", got.Score, tt.want)
}
})
}
Expand Down
1 change: 0 additions & 1 deletion checks/evaluation/dependency_update_tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

func TestDependencyUpdateTool(t *testing.T) {
t.Parallel()
//nolint
tests := []struct {
name string
findings []finding.Finding
Expand Down
4 changes: 2 additions & 2 deletions checks/evaluation/pinned_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

func Test_createScoreForGitHubActionsWorkflow(t *testing.T) {
t.Parallel()
//nolint
//nolint:govet
tests := []struct {
name string
r worklowPinningResult
Expand Down Expand Up @@ -884,7 +884,7 @@ func Test_addWorkflowPinnedResult(t *testing.T) {
w *worklowPinningResult
isGitHub bool
}
tests := []struct { //nolint:govet
tests := []struct {
name string
want *worklowPinningResult
args args
Expand Down
1 change: 0 additions & 1 deletion checks/evaluation/security_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

func TestSecurityPolicy(t *testing.T) {
t.Parallel()
//nolint
tests := []struct {
name string
findings []finding.Finding
Expand Down
3 changes: 2 additions & 1 deletion checks/evaluation/signed_releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ var (
const releaseLookBack = 5

// SignedReleases applies the score policy for the Signed-Releases check.
// nolint
//
//nolint:gocognit
func SignedReleases(name string, dl checker.DetailLogger, r *checker.SignedReleasesData) checker.CheckResult {
if r == nil {
e := sce.WithMessage(sce.ErrScorecardInternal, "empty raw data")
Expand Down
20 changes: 10 additions & 10 deletions checks/evaluation/vulnerabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ import (
// TestVulnerabilities tests the vulnerabilities checker.
func TestVulnerabilities(t *testing.T) {
t.Parallel()
//nolint
//nolint:govet
tests := []struct {
name string
findings []finding.Finding
result scut.TestReturn
findings []finding.Finding
result scut.TestReturn
expected []struct {
lineNumber uint
}
}{
{
name: "no vulnerabilities",
findings: []finding.Finding {
findings: []finding.Finding{
{
Probe: "hasOSVVulnerabilities",
Outcome: finding.OutcomePositive,
Expand All @@ -48,7 +48,7 @@ func TestVulnerabilities(t *testing.T) {
},
{
name: "three vulnerabilities",
findings: []finding.Finding {
findings: []finding.Finding{
{
Probe: "hasOSVVulnerabilities",
Outcome: finding.OutcomeNegative,
Expand All @@ -63,13 +63,13 @@ func TestVulnerabilities(t *testing.T) {
},
},
result: scut.TestReturn{
Score: 7,
Score: 7,
NumberOfWarn: 3,
},
},
{
name: "twelve vulnerabilities to check that score is not less than 0",
findings: []finding.Finding {
findings: []finding.Finding{
{
Probe: "hasOSVVulnerabilities",
Outcome: finding.OutcomeNegative,
Expand Down Expand Up @@ -120,13 +120,13 @@ func TestVulnerabilities(t *testing.T) {
},
},
result: scut.TestReturn{
Score: 0,
Score: 0,
NumberOfWarn: 12,
},
},
{
name: "invalid findings",
findings: []finding.Finding {},
name: "invalid findings",
findings: []finding.Finding{},
result: scut.TestReturn{
Score: -1,
Error: sce.ErrScorecardInternal,
Expand Down
Loading

0 comments on commit 92470de

Please sign in to comment.