mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-28 21:28:20 +00:00
Update to latest linters. Fix errors.
This commit is contained in:
@@ -1,25 +1,26 @@
|
||||
{
|
||||
"Disable": ["gotype", "gotypex", "maligned", "gocyclo", "golint"],
|
||||
"Disable": [
|
||||
"gotype",
|
||||
"gotypex",
|
||||
"maligned",
|
||||
"gocyclo",
|
||||
"golint"
|
||||
],
|
||||
"Enable": [
|
||||
"gosec",
|
||||
"errcheck",
|
||||
"deadcode",
|
||||
"gochecknoinits",
|
||||
"goconst",
|
||||
"gocyclo",
|
||||
"gofmt",
|
||||
"goimports",
|
||||
"golint",
|
||||
"gotype",
|
||||
"gotypex",
|
||||
"ineffassign",
|
||||
"interfacer",
|
||||
"maligned",
|
||||
"megacheck",
|
||||
"safesql",
|
||||
"staticcheck",
|
||||
"structcheck",
|
||||
"unconvert",
|
||||
"unparam",
|
||||
"varcheck",
|
||||
"vet",
|
||||
"vetshadow"
|
||||
@@ -27,7 +28,10 @@
|
||||
"Deadline": "300s",
|
||||
"Vendor": true,
|
||||
"LineLength": 120,
|
||||
"Skip": ["server/static", "mocks"],
|
||||
"Skip": [
|
||||
"server/static",
|
||||
"mocks"
|
||||
],
|
||||
"WarnUnmatchedDirective": true,
|
||||
"Linters": {
|
||||
"gosec": "gosec -exclude=G104 -fmt=csv:^(?P<path>.*?\\.go),(?P<line>\\d+),(?P<message>[^,]+,[^,]+,[^,]+)",
|
||||
|
||||
@@ -462,7 +462,7 @@ func (s *ServerCmd) setAtlantisURL(userConfig *server.UserConfig) error {
|
||||
if userConfig.AtlantisURL == "" {
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to determine hostname: %v", err)
|
||||
return errors.Wrap(err, "failed to determine hostname")
|
||||
}
|
||||
userConfig.AtlantisURL = fmt.Sprintf("http://%s:%d", hostname, userConfig.Port)
|
||||
}
|
||||
|
||||
@@ -158,7 +158,6 @@ func (t *E2ETester) Start() (*E2EResult, error) {
|
||||
return e2eResult, nil
|
||||
}
|
||||
|
||||
// nolint: unparam
|
||||
func getAtlantisStatus(t *E2ETester, branchName string) (string, error) {
|
||||
// check repo status
|
||||
combinedStatus, _, err := t.githubClient.client.Repositories.GetCombinedStatus(t.githubClient.ctx, t.ownerName, t.repoName, branchName, nil)
|
||||
@@ -184,7 +183,6 @@ func checkStatus(state string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// nolint: unparam
|
||||
func cleanUp(t *E2ETester, pullRequestNumber int, branchName string) error {
|
||||
// clean up
|
||||
pullClosed, _, err := t.githubClient.client.PullRequests.Edit(t.githubClient.ctx, t.ownerName, t.repoName, pullRequestNumber, &github.PullRequest{State: github.String("closed")})
|
||||
|
||||
@@ -136,7 +136,6 @@ func createAtlantisWebhook(g *GithubClient, ownerName string, repoName string, h
|
||||
return hook.GetID(), nil
|
||||
}
|
||||
|
||||
// nolint: unparam
|
||||
func deleteAtlantisHook(g *GithubClient, ownerName string, repoName string, hookID int64) error {
|
||||
_, err := g.client.Repositories.DeleteHook(g.ctx, ownerName, repoName, hookID)
|
||||
if err != nil {
|
||||
|
||||
@@ -32,14 +32,14 @@ var project = models.NewProject("owner/repo", "path")
|
||||
var workspace = "workspace"
|
||||
var pull = models.PullRequest{}
|
||||
var user = models.User{}
|
||||
var expectedErr = errors.New("err")
|
||||
var errExpected = errors.New("err")
|
||||
var timeNow = time.Now().Local()
|
||||
var pl = models.ProjectLock{Project: project, Pull: pull, User: user, Workspace: workspace, Time: timeNow}
|
||||
|
||||
func TestTryLock_Err(t *testing.T) {
|
||||
RegisterMockTestingT(t)
|
||||
backend := mocks.NewMockBackend()
|
||||
When(backend.TryLock(matchers.AnyModelsProjectLock())).ThenReturn(false, models.ProjectLock{}, expectedErr)
|
||||
When(backend.TryLock(matchers.AnyModelsProjectLock())).ThenReturn(false, models.ProjectLock{}, errExpected)
|
||||
t.Log("when the backend returns an error, TryLock should return that error")
|
||||
l := locking.NewClient(backend)
|
||||
_, err := l.TryLock(project, workspace, pull, user)
|
||||
@@ -70,7 +70,7 @@ func TestUnlock_InvalidKey(t *testing.T) {
|
||||
func TestUnlock_Err(t *testing.T) {
|
||||
RegisterMockTestingT(t)
|
||||
backend := mocks.NewMockBackend()
|
||||
When(backend.Unlock(matchers.AnyModelsProject(), AnyString())).ThenReturn(nil, expectedErr)
|
||||
When(backend.Unlock(matchers.AnyModelsProject(), AnyString())).ThenReturn(nil, errExpected)
|
||||
l := locking.NewClient(backend)
|
||||
_, err := l.Unlock("owner/repo/path/workspace")
|
||||
Equals(t, err, err)
|
||||
@@ -90,10 +90,10 @@ func TestUnlock(t *testing.T) {
|
||||
func TestList_Err(t *testing.T) {
|
||||
RegisterMockTestingT(t)
|
||||
backend := mocks.NewMockBackend()
|
||||
When(backend.List()).ThenReturn(nil, expectedErr)
|
||||
When(backend.List()).ThenReturn(nil, errExpected)
|
||||
l := locking.NewClient(backend)
|
||||
_, err := l.List()
|
||||
Equals(t, expectedErr, err)
|
||||
Equals(t, errExpected, err)
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
@@ -111,10 +111,10 @@ func TestList(t *testing.T) {
|
||||
func TestUnlockByPull(t *testing.T) {
|
||||
RegisterMockTestingT(t)
|
||||
backend := mocks.NewMockBackend()
|
||||
When(backend.UnlockByPull("owner/repo", 1)).ThenReturn(nil, expectedErr)
|
||||
When(backend.UnlockByPull("owner/repo", 1)).ThenReturn(nil, errExpected)
|
||||
l := locking.NewClient(backend)
|
||||
_, err := l.UnlockByPull("owner/repo", 1)
|
||||
Equals(t, expectedErr, err)
|
||||
Equals(t, errExpected, err)
|
||||
}
|
||||
|
||||
func TestGetLock_BadKey(t *testing.T) {
|
||||
@@ -129,10 +129,10 @@ func TestGetLock_BadKey(t *testing.T) {
|
||||
func TestGetLock_Err(t *testing.T) {
|
||||
RegisterMockTestingT(t)
|
||||
backend := mocks.NewMockBackend()
|
||||
When(backend.GetLock(project, workspace)).ThenReturn(nil, expectedErr)
|
||||
When(backend.GetLock(project, workspace)).ThenReturn(nil, errExpected)
|
||||
l := locking.NewClient(backend)
|
||||
_, err := l.GetLock("owner/repo/path/workspace")
|
||||
Equals(t, expectedErr, err)
|
||||
Equals(t, errExpected, err)
|
||||
}
|
||||
|
||||
func TestGetLock(t *testing.T) {
|
||||
|
||||
@@ -42,6 +42,5 @@ func (a *NotConfiguredVCSClient) UpdateStatus(repo models.Repo, pull models.Pull
|
||||
return a.err()
|
||||
}
|
||||
func (a *NotConfiguredVCSClient) err() error {
|
||||
//noinspection GoErrorStringFormat
|
||||
return fmt.Errorf("Atlantis was not configured to support repos from %s", a.Host.String())
|
||||
return fmt.Errorf("atlantis was not configured to support repos from %s", a.Host.String())
|
||||
}
|
||||
|
||||
@@ -203,7 +203,6 @@ func (l *SimpleLogger) levelToString(level LogLevel) string {
|
||||
|
||||
// callSite returns the location of the caller of this function via its
|
||||
// filename and line number. skip is the number of stack frames to skip.
|
||||
// nolint: unparam
|
||||
func (l *SimpleLogger) callSite(skip int) (string, int) {
|
||||
_, file, line, ok := runtime.Caller(skip)
|
||||
if !ok {
|
||||
|
||||
@@ -136,7 +136,6 @@ func getTunnelAddr() (string, error) {
|
||||
return "", fmt.Errorf("did not find ngrok tunnel with proto 'https' and config.addr '%s' in list of tunnels at %s\n%s", expAtlantisURL, tunAPI, string(body))
|
||||
}
|
||||
|
||||
// nolint: unparam
|
||||
func downloadAndUnzip(url string, path string, target string) error {
|
||||
if err := downloadFile(url, path); err != nil {
|
||||
return err
|
||||
@@ -208,8 +207,8 @@ func execAndWaitForStderr(wg *sync.WaitGroup, stderrMatch *regexp.Regexp, timeou
|
||||
// If it's a timeout we cancel the command ourselves.
|
||||
cancel()
|
||||
// We still need to wait for the command to finish.
|
||||
command.Wait() // nolint: errcheck
|
||||
return cancel, errChan, fmt.Errorf("timeout, logs:\n%s\n", log)
|
||||
command.Wait() // nolint: errcheck
|
||||
return cancel, errChan, fmt.Errorf("timeout, logs:\n%s\n", log) // nolint: staticcheck
|
||||
}
|
||||
|
||||
// Increment the wait group so callers can wait for the command to finish.
|
||||
|
||||
Reference in New Issue
Block a user