mirror of
https://github.com/ossf/scorecard.git
synced 2024-10-26 10:28:10 +03:00
🌱 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:
parent
6fb5f8a56e
commit
2391edfbe1
@ -51,16 +51,19 @@ linters:
|
||||
- ineffassign
|
||||
- lll
|
||||
- makezero
|
||||
- mirror
|
||||
- misspell
|
||||
- nakedret
|
||||
- nestif
|
||||
- predeclared
|
||||
- staticcheck
|
||||
- stylecheck
|
||||
- tenv
|
||||
- thelper
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unused
|
||||
- usestdlibvars
|
||||
- whitespace
|
||||
- wrapcheck
|
||||
presets:
|
||||
|
@ -16,7 +16,6 @@ package checks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
@ -27,8 +26,8 @@ import (
|
||||
scut "github.com/ossf/scorecard/v4/utests"
|
||||
)
|
||||
|
||||
//nolint:tparallel,paralleltest // since t.Setenv is used
|
||||
func TestWebhooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
tests := []struct {
|
||||
expected checker.CheckResult
|
||||
uri string
|
||||
@ -96,9 +95,7 @@ func TestWebhooks(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
tt := tt // Re-initializing variable so it is not changed while executing the closure below
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
os.Setenv("SCORECARD_EXPERIMENTAL", "true")
|
||||
t.Setenv("SCORECARD_EXPERIMENTAL", "true")
|
||||
ctrl := gomock.NewController(t)
|
||||
mockRepo := mockrepo.NewMockRepoClient(ctrl)
|
||||
|
||||
|
@ -50,7 +50,7 @@ func (transport *expBackoffTransport) RoundTrip(req *http.Request) (*http.Respon
|
||||
func (client *httpClientCIIBestPractices) GetBadgeLevel(ctx context.Context, uri string) (BadgeLevel, error) {
|
||||
repoURI := fmt.Sprintf("https://%s", uri)
|
||||
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 {
|
||||
return Unknown, fmt.Errorf("error during http.NewRequestWithContext: %w", err)
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ package gitlabrepo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@ -84,10 +85,10 @@ func (handler *branchesHandler) setup() error {
|
||||
if branch.Protected {
|
||||
protectedBranch, resp, err := handler.getProtectedBranch(
|
||||
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)
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ func TestGetBranches(t *testing.T) {
|
||||
},
|
||||
returnStatus: &gitlab.Response{
|
||||
Response: &http.Response{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
},
|
||||
},
|
||||
branchReturn: &gitlab.ProtectedBranch{},
|
||||
@ -69,7 +69,7 @@ func TestGetBranches(t *testing.T) {
|
||||
},
|
||||
returnStatus: &gitlab.Response{
|
||||
Response: &http.Response{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -16,6 +16,7 @@ package gitlabrepo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
@ -53,7 +54,7 @@ func (handler *issuesHandler) setup() error {
|
||||
if err != nil && resp.StatusCode != 401 {
|
||||
handler.errSetup = fmt.Errorf("unable to find access tokens associated with the project id: %w", err)
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -608,7 +608,7 @@ func testResult(wantErr bool, responseFileName string) (*http.Response, error) {
|
||||
}
|
||||
if wantErr && responseFileName == "text" {
|
||||
return &http.Response{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString("text")),
|
||||
}, nil
|
||||
}
|
||||
@ -617,7 +617,7 @@ func testResult(wantErr bool, responseFileName string) (*http.Response, error) {
|
||||
return nil, fmt.Errorf("%w", err)
|
||||
}
|
||||
return &http.Response{
|
||||
StatusCode: 200,
|
||||
Body: io.NopCloser(bytes.NewBufferString(string(content))),
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBuffer(content)),
|
||||
}, nil
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ func Test_fetchGitRepositoryFromNPM(t *testing.T) {
|
||||
}
|
||||
|
||||
return &http.Response{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString(tt.args.result)),
|
||||
}, nil
|
||||
}).AnyTimes()
|
||||
@ -456,7 +456,7 @@ func Test_fetchGitRepositoryFromPYPI(t *testing.T) {
|
||||
}
|
||||
|
||||
return &http.Response{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString(tt.args.result)),
|
||||
}, nil
|
||||
}).AnyTimes()
|
||||
@ -725,7 +725,7 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) {
|
||||
}
|
||||
|
||||
return &http.Response{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString(tt.args.result)),
|
||||
}, nil
|
||||
}).AnyTimes()
|
||||
|
Loading…
Reference in New Issue
Block a user