🌱 add style linters: mirror, tenv, usestdlibvars (#3586)

* fix tenv linter and bug with t.Parallel

Signed-off-by: Spencer Schrock <sschrock@google.com>

* fix usestdlibvars linter

Signed-off-by: Spencer Schrock <sschrock@google.com>

* fix mirror linter

Signed-off-by: Spencer Schrock <sschrock@google.com>

---------

Signed-off-by: Spencer Schrock <sschrock@google.com>
This commit is contained in:
Spencer Schrock 2023-10-23 15:40:01 -07:00 committed by GitHub
parent 6fb5f8a56e
commit 2391edfbe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 19 additions and 17 deletions

View File

@ -51,16 +51,19 @@ linters:
- ineffassign - ineffassign
- lll - lll
- makezero - makezero
- mirror
- misspell - misspell
- nakedret - nakedret
- nestif - nestif
- predeclared - predeclared
- staticcheck - staticcheck
- stylecheck - stylecheck
- tenv
- thelper - thelper
- typecheck - typecheck
- unconvert - unconvert
- unused - unused
- usestdlibvars
- whitespace - whitespace
- wrapcheck - wrapcheck
presets: presets:

View File

@ -16,7 +16,6 @@ package checks
import ( import (
"context" "context"
"os"
"testing" "testing"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
@ -27,8 +26,8 @@ import (
scut "github.com/ossf/scorecard/v4/utests" scut "github.com/ossf/scorecard/v4/utests"
) )
//nolint:tparallel,paralleltest // since t.Setenv is used
func TestWebhooks(t *testing.T) { func TestWebhooks(t *testing.T) {
t.Parallel()
tests := []struct { tests := []struct {
expected checker.CheckResult expected checker.CheckResult
uri string uri string
@ -96,9 +95,7 @@ func TestWebhooks(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below tt := tt // Re-initializing variable so it is not changed while executing the closure below
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
t.Parallel() t.Setenv("SCORECARD_EXPERIMENTAL", "true")
os.Setenv("SCORECARD_EXPERIMENTAL", "true")
ctrl := gomock.NewController(t) ctrl := gomock.NewController(t)
mockRepo := mockrepo.NewMockRepoClient(ctrl) mockRepo := mockrepo.NewMockRepoClient(ctrl)

View File

@ -50,7 +50,7 @@ func (transport *expBackoffTransport) RoundTrip(req *http.Request) (*http.Respon
func (client *httpClientCIIBestPractices) GetBadgeLevel(ctx context.Context, uri string) (BadgeLevel, error) { func (client *httpClientCIIBestPractices) GetBadgeLevel(ctx context.Context, uri string) (BadgeLevel, error) {
repoURI := fmt.Sprintf("https://%s", uri) repoURI := fmt.Sprintf("https://%s", uri)
url := fmt.Sprintf("https://www.bestpractices.dev/projects.json?url=%s", repoURI) url := fmt.Sprintf("https://www.bestpractices.dev/projects.json?url=%s", repoURI)
req, err := http.NewRequestWithContext(ctx, "GET", url, nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil { if err != nil {
return Unknown, fmt.Errorf("error during http.NewRequestWithContext: %w", err) return Unknown, fmt.Errorf("error during http.NewRequestWithContext: %w", err)
} }

View File

@ -16,6 +16,7 @@ package gitlabrepo
import ( import (
"fmt" "fmt"
"net/http"
"strings" "strings"
"sync" "sync"
@ -84,10 +85,10 @@ func (handler *branchesHandler) setup() error {
if branch.Protected { if branch.Protected {
protectedBranch, resp, err := handler.getProtectedBranch( protectedBranch, resp, err := handler.getProtectedBranch(
handler.repourl.projectID, branch.Name) handler.repourl.projectID, branch.Name)
if err != nil && resp.StatusCode != 403 { if err != nil && resp.StatusCode != http.StatusForbidden {
handler.errSetup = fmt.Errorf("request for protected branch failed with error %w", err) handler.errSetup = fmt.Errorf("request for protected branch failed with error %w", err)
return return
} else if resp.StatusCode == 403 { } else if resp.StatusCode == http.StatusForbidden {
handler.errSetup = fmt.Errorf("incorrect permissions to fully check branch protection %w", err) handler.errSetup = fmt.Errorf("incorrect permissions to fully check branch protection %w", err)
return return
} }

View File

@ -52,7 +52,7 @@ func TestGetBranches(t *testing.T) {
}, },
returnStatus: &gitlab.Response{ returnStatus: &gitlab.Response{
Response: &http.Response{ Response: &http.Response{
StatusCode: 200, StatusCode: http.StatusOK,
}, },
}, },
branchReturn: &gitlab.ProtectedBranch{}, branchReturn: &gitlab.ProtectedBranch{},
@ -69,7 +69,7 @@ func TestGetBranches(t *testing.T) {
}, },
returnStatus: &gitlab.Response{ returnStatus: &gitlab.Response{
Response: &http.Response{ Response: &http.Response{
StatusCode: 200, StatusCode: http.StatusOK,
}, },
}, },
}, },

View File

@ -16,6 +16,7 @@ package gitlabrepo
import ( import (
"fmt" "fmt"
"net/http"
"sync" "sync"
"github.com/xanzy/go-gitlab" "github.com/xanzy/go-gitlab"
@ -53,7 +54,7 @@ func (handler *issuesHandler) setup() error {
if err != nil && resp.StatusCode != 401 { if err != nil && resp.StatusCode != 401 {
handler.errSetup = fmt.Errorf("unable to find access tokens associated with the project id: %w", err) handler.errSetup = fmt.Errorf("unable to find access tokens associated with the project id: %w", err)
return return
} else if resp.StatusCode == 401 { } else if resp.StatusCode == http.StatusUnauthorized {
handler.errSetup = fmt.Errorf("insufficient permissions to check issue author associations %w", err) handler.errSetup = fmt.Errorf("insufficient permissions to check issue author associations %w", err)
return return
} }

View File

@ -608,7 +608,7 @@ func testResult(wantErr bool, responseFileName string) (*http.Response, error) {
} }
if wantErr && responseFileName == "text" { if wantErr && responseFileName == "text" {
return &http.Response{ return &http.Response{
StatusCode: 200, StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString("text")), Body: io.NopCloser(bytes.NewBufferString("text")),
}, nil }, nil
} }
@ -617,7 +617,7 @@ func testResult(wantErr bool, responseFileName string) (*http.Response, error) {
return nil, fmt.Errorf("%w", err) return nil, fmt.Errorf("%w", err)
} }
return &http.Response{ return &http.Response{
StatusCode: 200, StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(string(content))), Body: io.NopCloser(bytes.NewBuffer(content)),
}, nil }, nil
} }

View File

@ -146,7 +146,7 @@ func Test_fetchGitRepositoryFromNPM(t *testing.T) {
} }
return &http.Response{ return &http.Response{
StatusCode: 200, StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(tt.args.result)), Body: io.NopCloser(bytes.NewBufferString(tt.args.result)),
}, nil }, nil
}).AnyTimes() }).AnyTimes()
@ -456,7 +456,7 @@ func Test_fetchGitRepositoryFromPYPI(t *testing.T) {
} }
return &http.Response{ return &http.Response{
StatusCode: 200, StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(tt.args.result)), Body: io.NopCloser(bytes.NewBufferString(tt.args.result)),
}, nil }, nil
}).AnyTimes() }).AnyTimes()
@ -725,7 +725,7 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) {
} }
return &http.Response{ return &http.Response{
StatusCode: 200, StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(tt.args.result)), Body: io.NopCloser(bytes.NewBufferString(tt.args.result)),
}, nil }, nil
}).AnyTimes() }).AnyTimes()