Skip to content

Commit

Permalink
🌱 Bump github.com/golangci/golangci-lint from 1.57.2 to 1.58.1 in /to…
Browse files Browse the repository at this point in the history
…ols (#4108)
  • Loading branch information
dependabot[bot] committed May 15, 2024
1 parent 4a078ca commit 0082cad
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 458 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ issues:
exclude-rules:
- path: '(.+)_test\.go'
linters:
- err113
- funlen
- goconst
- gocyclo
- goerr113
- lll
- wrapcheck
# probes must register via init
Expand All @@ -31,6 +31,7 @@ linters:
enable:
- asciicheck
- dogsled
- err113
- errcheck
- errname
- errorlint
Expand All @@ -45,7 +46,6 @@ linters:
- gocyclo
- godot
- godox
- goerr113
- gofmt
- gofumpt
- goheader
Expand Down
72 changes: 36 additions & 36 deletions checks/evaluation/branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@ func BranchProtection(name string,
branchScores[branchName] = &levelScore{}
}

var score, max int
var score, maxScore int

doLogging := protectedBranches[branchName]
switch f.Probe {
case blocksDeleteOnBranches.Probe, blocksForcePushOnBranches.Probe:
score, max = deleteAndForcePushProtection(f, doLogging, dl)
score, maxScore = deleteAndForcePushProtection(f, doLogging, dl)
branchScores[branchName].scores.basic += score
branchScores[branchName].maxes.basic += max
branchScores[branchName].maxes.basic += maxScore

case dismissesStaleReviews.Probe, branchProtectionAppliesToAdmins.Probe:
score, max = adminThoroughReviewProtection(f, doLogging, dl)
score, maxScore = adminThoroughReviewProtection(f, doLogging, dl)
branchScores[branchName].scores.adminThoroughReview += score
branchScores[branchName].maxes.adminThoroughReview += max
branchScores[branchName].maxes.adminThoroughReview += maxScore

case requiresApproversForPullRequests.Probe:
noOfRequiredReviewers, err := getReviewerCount(f)
Expand All @@ -175,32 +175,32 @@ func BranchProtection(name string,
// Scorecard evaluation scores twice with this probe:
// Once if the count is above 0
// Once if the count is above 2
score, max = logReviewerCount(f, doLogging, dl, noOfRequiredReviewers)
score, maxScore = logReviewerCount(f, doLogging, dl, noOfRequiredReviewers)
branchScores[branchName].scores.thoroughReview += score
branchScores[branchName].maxes.thoroughReview += max
branchScores[branchName].maxes.thoroughReview += maxScore

reviewerWeight := 2
max = reviewerWeight
maxScore = reviewerWeight
if f.Outcome == finding.OutcomeTrue && noOfRequiredReviewers > 0 {
branchScores[branchName].scores.review += reviewerWeight
}
branchScores[branchName].maxes.review += max
branchScores[branchName].maxes.review += maxScore

case requiresCodeOwnersReview.Probe:
score, max = codeownerBranchProtection(f, doLogging, dl)
score, maxScore = codeownerBranchProtection(f, doLogging, dl)
branchScores[branchName].scores.codeownerReview += score
branchScores[branchName].maxes.codeownerReview += max
branchScores[branchName].maxes.codeownerReview += maxScore

case requiresUpToDateBranches.Probe, requiresLastPushApproval.Probe,
requiresPRsToChangeCode.Probe:
score, max = adminReviewProtection(f, doLogging, dl)
score, maxScore = adminReviewProtection(f, doLogging, dl)
branchScores[branchName].scores.adminReview += score
branchScores[branchName].maxes.adminReview += max
branchScores[branchName].maxes.adminReview += maxScore

case runsStatusChecksBeforeMerging.Probe:
score, max = nonAdminContextProtection(f, doLogging, dl)
score, maxScore = nonAdminContextProtection(f, doLogging, dl)
branchScores[branchName].scores.context += score
branchScores[branchName].maxes.context += max
branchScores[branchName].maxes.context += maxScore
}
}

Expand Down Expand Up @@ -308,11 +308,11 @@ func logInfoOrWarn(f *finding.Finding, doLogging bool, dl checker.DetailLogger)
}
}

func normalizeScore(score, max, level int) float64 {
if max == 0 {
func normalizeScore(score, maxScore, level int) float64 {
if maxScore == 0 {
return float64(level)
}
return float64(score*level) / float64(max)
return float64(score*level) / float64(maxScore)
}

func computeFinalScore(scores []levelScore) (int, error) {
Expand Down Expand Up @@ -402,53 +402,53 @@ func warn(dl checker.DetailLogger, doLogging bool, desc string, args ...interfac
}

func deleteAndForcePushProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
var score, maxScore int
logWithoutDebug(f, doLogging, dl)
if f.Outcome == finding.OutcomeTrue {
score++
}
max++
maxScore++

return score, max
return score, maxScore
}

func nonAdminContextProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
var score, maxScore int
logInfoOrWarn(f, doLogging, dl)
if f.Outcome == finding.OutcomeTrue {
score++
}
max++
return score, max
maxScore++
return score, maxScore
}

func adminReviewProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
var score, maxScore int
if f.Outcome == finding.OutcomeTrue {
score++
}
logWithDebug(f, doLogging, dl)
if f.Outcome != finding.OutcomeNotAvailable {
max++
maxScore++
}
return score, max
return score, maxScore
}

func adminThoroughReviewProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
var score, maxScore int

logWithDebug(f, doLogging, dl)
if f.Outcome == finding.OutcomeTrue {
score++
}
if f.Outcome != finding.OutcomeNotAvailable {
max++
maxScore++
}
return score, max
return score, maxScore
}

func logReviewerCount(f *finding.Finding, doLogging bool, dl checker.DetailLogger, noOfRequiredReviews int) (int, int) {
var score, max int
var score, maxScore int
if f.Outcome == finding.OutcomeTrue {
if noOfRequiredReviews >= minReviews {
info(dl, doLogging, f.Message)
Expand All @@ -459,18 +459,18 @@ func logReviewerCount(f *finding.Finding, doLogging bool, dl checker.DetailLogge
} else if f.Outcome == finding.OutcomeFalse {
warn(dl, doLogging, f.Message)
}
max++
return score, max
maxScore++
return score, maxScore
}

func codeownerBranchProtection(f *finding.Finding, doLogging bool, dl checker.DetailLogger) (int, int) {
var score, max int
var score, maxScore int
if f.Outcome == finding.OutcomeTrue {
info(dl, doLogging, f.Message)
score++
} else {
warn(dl, doLogging, f.Message)
}
max++
return score, max
maxScore++
return score, maxScore
}
6 changes: 3 additions & 3 deletions checks/raw/binary_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ var checkBinaryFileReader fileparser.DoWhileTrueOnFileReader = func(path string,
// A version of golang.org/x/tools/godoc/util modified to allow carriage returns
// and utf8.RuneError (0xFFFD), as the file may not be utf8 encoded.
func isText(s []byte) bool {
const max = binaryTestLen // at least utf8.UTFMax (4)
if len(s) > max {
s = s[0:max]
const maxLen = binaryTestLen // at least utf8.UTFMax (4)
if len(s) > maxLen {
s = s[0:maxLen]
}
for i, c := range string(s) {
if i+utf8.UTFMax > len(s) {
Expand Down
Loading

0 comments on commit 0082cad

Please sign in to comment.