Skip to content

Commit

Permalink
🌱 Fix linter issues caught by new linters in golangci-lint v1.55.0 (o…
Browse files Browse the repository at this point in the history
…ssf#3603)

* fix protogetter issues

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

* de-dupe property based fuzzer description

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

---------

Signed-off-by: Spencer Schrock <[email protected]>
Signed-off-by: Allen Shearin <[email protected]>
  • Loading branch information
spencerschrock authored and ashearin committed Nov 13, 2023
1 parent ad97195 commit 7c9eea0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
18 changes: 9 additions & 9 deletions checks/raw/fuzzing.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ var languageFuzzSpecs = map[clients.LanguageName]languageFuzzConfig{
// or their indirect imports through the higher-level Hspec or Tasty testing frameworks.
funcPattern: `import\s+(qualified\s+)?Test\.((Hspec|Tasty)\.)?(QuickCheck|Hedgehog|Validity|SmallCheck)`,
Name: fuzzerPropertyBasedHaskell,
Desc: asPointer(
"Property-based testing in Haskell generates test instances randomly or exhaustively " +
"and test that specific properties are satisfied."),
Desc: propertyBasedDescription("Haskell"),
},
// Fuzz patterns for JavaScript and TypeScript based on property-based testing.
//
Expand All @@ -110,19 +108,15 @@ var languageFuzzSpecs = map[clients.LanguageName]languageFuzzConfig{
funcPattern: `(from\s+['"](fast-check|@fast-check/(ava|jest|vitest))['"]|` +
`require\(\s*['"](fast-check|@fast-check/(ava|jest|vitest))['"]\s*\))`,
Name: fuzzerPropertyBasedJavaScript,
Desc: asPointer(
"Property-based testing in JavaScript generates test instances randomly or exhaustively " +
"and test that specific properties are satisfied."),
Desc: propertyBasedDescription("JavaScript"),
},
clients.TypeScript: {
filePatterns: []string{"*.ts"},
// Look for direct imports of fast-check and its test runners integrations.
funcPattern: `(from\s+['"](fast-check|@fast-check/(ava|jest|vitest))['"]|` +
`require\(\s*['"](fast-check|@fast-check/(ava|jest|vitest))['"]\s*\))`,
Name: fuzzerPropertyBasedTypeScript,
Desc: asPointer(
"Property-based testing in TypeScript generates test instances randomly or exhaustively " +
"and test that specific properties are satisfied."),
Desc: propertyBasedDescription("TypeScript"),
},
clients.Python: {
filePatterns: []string{"*.py"},
Expand Down Expand Up @@ -387,3 +381,9 @@ func getProminentLanguages(langs []clients.Language) []clients.LanguageName {
}
return ret
}

func propertyBasedDescription(language string) *string {
s := fmt.Sprintf("Property-based testing in %s generates test instances randomly or exhaustively "+
"and test that specific properties are satisfied.", language)
return &s
}
1 change: 1 addition & 0 deletions cron/internal/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func localFiles(filenames []string) (data.Iterator, error) {
return iter, nil
}

//nolint:protogetter // this is a false positive https://github.com/ghostiam/protogetter/issues/4
func main() {
ctx := context.Background()
t := time.Now().UTC()
Expand Down
4 changes: 2 additions & 2 deletions cron/internal/pubsub/subscriber_gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (subscriber *gcsSubscriber) SynchronousPull() (*data.ScorecardBatchRequest,
log.Printf("error during Recieive: %v", err)
return nil, nil
}
numReceivedMessages = len(result.ReceivedMessages)
numReceivedMessages = len(result.GetReceivedMessages())
if numReceivedMessages > 0 {
msgToProcess = result.GetReceivedMessages()[0]
} else {
Expand All @@ -107,7 +107,7 @@ func (subscriber *gcsSubscriber) SynchronousPull() (*data.ScorecardBatchRequest,
log.Fatalf("expected to receive max %d messages, got %d", maxMessagesToPull, numReceivedMessages)
}

subscriber.recvdAckID = msgToProcess.AckId
subscriber.recvdAckID = msgToProcess.GetAckId()
// Continuously notify the server that processing is still happening on this message.
go subscriber.extendAckDeadline()

Expand Down
12 changes: 6 additions & 6 deletions cron/internal/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,25 +174,25 @@ func processRequest(ctx context.Context,
var rawBuffer bytes.Buffer
// TODO: run Scorecard for each repo in a separate thread.
for _, repoReq := range batchRequest.GetRepos() {
logger.Info(fmt.Sprintf("Running Scorecard for repo: %s", *repoReq.Url))
logger.Info(fmt.Sprintf("Running Scorecard for repo: %s", repoReq.GetUrl()))
var repo clients.Repo
var err error
repoClient := githubClient
disabledChecks := blacklistedChecks
if repo, err = gitlabrepo.MakeGitlabRepo(*repoReq.Url); err == nil { // repo is a gitlab url
if repo, err = gitlabrepo.MakeGitlabRepo(repoReq.GetUrl()); err == nil { // repo is a gitlab url
repoClient = gitlabClient
disabledChecks = gitlabDisabledChecks
} else if repo, err = githubrepo.MakeGithubRepo(*repoReq.Url); err != nil {
} else if repo, err = githubrepo.MakeGithubRepo(repoReq.GetUrl()); err != nil {
// TODO(log): Previously Warn. Consider logging an error here.
logger.Info(fmt.Sprintf("URL was neither valid GitLab nor GitHub: %v", err))
continue
}
repo.AppendMetadata(repoReq.Metadata...)
repo.AppendMetadata(repoReq.GetMetadata()...)

commitSHA := clients.HeadSHA
requiredRequestType := []checker.RequestType{}
if repoReq.Commit != nil && *repoReq.Commit != clients.HeadSHA {
commitSHA = *repoReq.Commit
if repoReq.GetCommit() != clients.HeadSHA {
commitSHA = repoReq.GetCommit()
requiredRequestType = append(requiredRequestType, checker.CommitBased)
}
checksToRun, err := policy.GetEnabled(nil /*policy*/, nil /*checks*/, requiredRequestType)
Expand Down
2 changes: 1 addition & 1 deletion policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func GetEnabled(

func checksHavePolicies(sp *ScorecardPolicy, enabledChecks checker.CheckNameToFnMap) bool {
for checkName := range enabledChecks {
_, exists := sp.Policies[checkName]
_, exists := sp.GetPolicies()[checkName]
if !exists {
log.Printf("check %s has no policy declared", checkName)
return false
Expand Down
6 changes: 3 additions & 3 deletions policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestChecksHavePolicies(t *testing.T) {
t.Error("Expected checks to have policies")
}

delete(sp.Policies, "Binary-Artifacts")
delete(sp.GetPolicies(), "Binary-Artifacts")
// Call the function being tested
result = checksHavePolicies(sp, check)

Expand Down Expand Up @@ -246,8 +246,8 @@ func TestParseFromFile(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if len(sp.Policies) != 3 {
t.Errorf("Unexpected number of policies: got %v, want %v", len(sp.Policies), 3)
if len(sp.GetPolicies()) != 3 {
t.Errorf("Unexpected number of policies: got %v, want %v", len(sp.GetPolicies()), 3)
}
invalidPolicy := "testdata/policy-invalid-score-0.yaml"
_, err = ParseFromFile(invalidPolicy)
Expand Down

0 comments on commit 7c9eea0

Please sign in to comment.