Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsimon committed Jul 16, 2021
1 parent 49de1ab commit cecf71a
Show file tree
Hide file tree
Showing 22 changed files with 33 additions and 29 deletions.
8 changes: 6 additions & 2 deletions checker/check_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const (
MinResultConfidence = 0
)

// UPGRADEv2: to remove.
// ErrorDemoninatorZero indicates the denominator for a proportional result is 0.
// UPGRADEv2: to remove.
var ErrorDemoninatorZero = errors.New("internal error: denominator is 0")

//nolint
Expand Down Expand Up @@ -172,6 +172,8 @@ func MakeAndResult2(checks ...CheckResult) CheckResult {

worseResult := checks[0]

// UPGRADEv2: will go away after old struct is removed.
//nolint
for _, result := range checks[1:] {
if result.Score2 < worseResult.Score2 {
worseResult = result
Expand Down Expand Up @@ -248,6 +250,7 @@ func MakeProportionalResult(name string, numerator int, denominator int,
}

// Given a min result, check if another result is worse.
//nolint
func isMinResult(result, min CheckResult) bool {
if Bool2int(result.Pass) < Bool2int(min.Pass) {
return true
Expand All @@ -267,7 +270,8 @@ func MakeAndResult(checks ...CheckResult) CheckResult {
Pass: true,
Confidence: MaxResultConfidence,
}

// UPGRADEv2: will go away after old struct is removed.
//nolint
for _, result := range checks {
if minResult.Name == "" {
minResult.Name = result.Name
Expand Down
4 changes: 2 additions & 2 deletions checker/check_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (l *logger) Logf(s string, f ...interface{}) {
l.messages = append(l.messages, fmt.Sprintf(s, f...))
}

func logStats(ctx context.Context, startTime time.Time, result CheckResult) error {
func logStats(ctx context.Context, startTime time.Time, result *CheckResult) error {
runTimeInSecs := time.Now().Unix() - startTime.Unix()
opencensusstats.Record(ctx, stats.CheckRuntimeInSec.M(runTimeInSecs))

Expand Down Expand Up @@ -130,7 +130,7 @@ func (r *Runner) Run(ctx context.Context, f CheckFn) CheckResult {
res.Details = l.messages
res.Details2 = l.messages2

if err := logStats(ctx, startTime, res); err != nil {
if err := logStats(ctx, startTime, &res); err != nil {
panic(err)
}
return res
Expand Down
2 changes: 1 addition & 1 deletion checker/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func TestMakeCheckAnd(t *testing.T) {
t.Parallel()
tests := []struct {
name string
checks []CheckResult
want CheckResult
checks []CheckResult
}{
{
name: "Multiple passing",
Expand Down
1 change: 0 additions & 1 deletion checks/active.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"time"

"github.com/google/go-github/v32/github"

"github.com/ossf/scorecard/checker"
)

Expand Down
1 change: 0 additions & 1 deletion checks/binary_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"github.com/h2non/filetype"
"github.com/h2non/filetype/types"

"github.com/ossf/scorecard/checker"
sce "github.com/ossf/scorecard/errors"
)
Expand Down
1 change: 0 additions & 1 deletion checks/branch_protected.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"regexp"

"github.com/google/go-github/v32/github"

"github.com/ossf/scorecard/checker"
)

Expand Down
2 changes: 1 addition & 1 deletion checks/branch_protected_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"testing"

"github.com/google/go-github/v32/github"

"github.com/ossf/scorecard/checker"
)

Expand Down Expand Up @@ -88,6 +87,7 @@ func TestReleaseAndDevBranchProtected(t *testing.T) { //nolint:tparallel // mock
rel1 := "release/v.1"
sha := "8fb3cb86082b17144a80402f5367ae65f06083bd"
main := "main"
//nolint
tests := []struct {
name string
branches []*string
Expand Down
1 change: 0 additions & 1 deletion checks/ci_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"strings"

"github.com/google/go-github/v32/github"

"github.com/ossf/scorecard/checker"
)

Expand Down
3 changes: 1 addition & 2 deletions checks/code_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import (
"strings"

"github.com/google/go-github/v32/github"
"github.com/shurcooL/githubv4"

"github.com/ossf/scorecard/checker"
"github.com/shurcooL/githubv4"
)

const (
Expand Down
1 change: 0 additions & 1 deletion checks/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"strings"

"github.com/google/go-github/v32/github"

"github.com/ossf/scorecard/checker"
)

Expand Down
1 change: 0 additions & 1 deletion checks/fuzzing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"

"github.com/google/go-github/v32/github"

"github.com/ossf/scorecard/checker"
)

Expand Down
1 change: 0 additions & 1 deletion checks/packaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"strings"

"github.com/google/go-github/v32/github"

"github.com/ossf/scorecard/checker"
)

Expand Down
3 changes: 1 addition & 2 deletions checks/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import (
"fmt"
"strings"

"gopkg.in/yaml.v2"

"github.com/ossf/scorecard/checker"
sce "github.com/ossf/scorecard/errors"
"gopkg.in/yaml.v2"
)

const CheckPermissions = "Token-Permissions"
Expand Down
1 change: 0 additions & 1 deletion checks/pull_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"strings"

"github.com/google/go-github/v32/github"

"github.com/ossf/scorecard/checker"
)

Expand Down
1 change: 0 additions & 1 deletion checks/sast.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"errors"

"github.com/google/go-github/v32/github"

"github.com/ossf/scorecard/checker"
)

Expand Down
1 change: 0 additions & 1 deletion checks/signed_releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"strings"

"github.com/google/go-github/v32/github"

"github.com/ossf/scorecard/checker"
)

Expand Down
3 changes: 1 addition & 2 deletions checks/signed_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ package checks
import (
"errors"

"github.com/shurcooL/githubv4"

"github.com/ossf/scorecard/checker"
"github.com/shurcooL/githubv4"
)

const (
Expand Down
1 change: 0 additions & 1 deletion checks/vulnerabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"strings"

"github.com/google/go-github/v32/github"

"github.com/ossf/scorecard/checker"
)

Expand Down
1 change: 1 addition & 0 deletions e2e/automatic_deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//nolint:dupl
package e2e

import (
Expand Down
1 change: 1 addition & 0 deletions e2e/binary_artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//nolint:dupl
package e2e

import (
Expand Down
7 changes: 3 additions & 4 deletions pkg/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ import (
"time"

"github.com/google/go-github/v32/github"
"github.com/shurcooL/githubv4"
opencensusstats "go.opencensus.io/stats"
"go.opencensus.io/tag"

"github.com/ossf/scorecard/checker"
"github.com/ossf/scorecard/clients"
"github.com/ossf/scorecard/repos"
"github.com/ossf/scorecard/stats"
"github.com/shurcooL/githubv4"
opencensusstats "go.opencensus.io/stats"
"go.opencensus.io/tag"
)

func logStats(ctx context.Context, startTime time.Time) {
Expand Down
17 changes: 15 additions & 2 deletions pkg/scorecard_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func (r *ScorecardResult) AsJSON(showDetails bool, logLevel zapcore.Level, write
Date: r.Date,
Metadata: r.Metadata,
}
// UPGRADEv2: remove nolint after uggrade.
//nolint
for _, checkResult := range r.Checks {
tmpResult := checker.CheckResult{
Name: checkResult.Name,
Expand All @@ -69,6 +71,8 @@ func (r *ScorecardResult) AsCSV(showDetails bool, logLevel zapcore.Level, writer
w := csv.NewWriter(writer)
record := []string{r.Repo}
columns := []string{"Repository"}
// UPGRADEv2: remove nolint after uggrade.
//nolint
for _, checkResult := range r.Checks {
columns = append(columns, checkResult.Name+"_Pass", checkResult.Name+"_Confidence")
record = append(record, strconv.FormatBool(checkResult.Pass),
Expand All @@ -92,6 +96,7 @@ func (r *ScorecardResult) AsCSV(showDetails bool, logLevel zapcore.Level, writer
// UPGRADEv2: will be removed.
func (r *ScorecardResult) AsString(showDetails bool, logLevel zapcore.Level, writer io.Writer) error {
sortedChecks := make([]checker.CheckResult, len(r.Checks))
//nolint
for i, checkResult := range r.Checks {
sortedChecks[i] = checkResult
}
Expand All @@ -103,6 +108,7 @@ func (r *ScorecardResult) AsString(showDetails bool, logLevel zapcore.Level, wri
})

data := make([][]string, len(sortedChecks))
//nolint
for i, row := range sortedChecks {
const withdetails = 4
const withoutdetails = 3
Expand All @@ -120,7 +126,7 @@ func (r *ScorecardResult) AsString(showDetails bool, logLevel zapcore.Level, wri
if showDetails {
//nolint
if row.Version == 2 {
sa := make([]string, 1)
var sa []string
for _, v := range row.Details2 {
if v.Type == checker.DetailDebug && logLevel != zapcore.DebugLevel {
continue
Expand Down Expand Up @@ -155,6 +161,8 @@ func (r *ScorecardResult) AsString(showDetails bool, logLevel zapcore.Level, wri
// UPGRADEv2: new code.
func (r *ScorecardResult) AsString2(showDetails bool, logLevel zapcore.Level, writer io.Writer) error {
sortedChecks := make([]checker.CheckResult, len(r.Checks))
//nolint
// UPGRADEv2: not needed after upgrade.
for i, checkResult := range r.Checks {
sortedChecks[i] = checkResult
}
Expand All @@ -166,6 +174,8 @@ func (r *ScorecardResult) AsString2(showDetails bool, logLevel zapcore.Level, wr
})

data := make([][]string, len(sortedChecks))
//nolint
// UPGRADEv2: not needed after upgrade.
for i, row := range sortedChecks {
//nolint
if row.Version != 2 {
Expand All @@ -192,7 +202,9 @@ func (r *ScorecardResult) AsString2(showDetails bool, logLevel zapcore.Level, wr
x[1] = row.Reason2
x[2] = row.Name
if showDetails {
sa := make([]string, 1)
// UPGRADEv2: change to make([]string, len(row.Details))
// followed by sa[i] = instead of append
var sa []string
for _, v := range row.Details2 {
if v.Type == checker.DetailDebug && logLevel != zapcore.DebugLevel {
continue
Expand Down Expand Up @@ -240,6 +252,7 @@ func typeToString(cd checker.DetailType) string {
}
}

// UPGRADEv2: not needed after upgrade.
func displayResult(result bool) string {
if result {
return "Pass"
Expand Down

0 comments on commit cecf71a

Please sign in to comment.