From 62fd4641a640bb468ceb4a9fe518d990434f3c17 Mon Sep 17 00:00:00 2001 From: Alexander Melentyev Date: Sun, 26 Sep 2021 23:32:08 +0300 Subject: [PATCH] Fix linters issues --- .golangci.yml | 4 ++-- example/commitpr/main.go | 4 ++-- github/actions_workflow_jobs.go | 1 - github/actions_workflow_runs_test.go | 1 - github/enterprise_audit_log_test.go | 1 - github/github.go | 10 +++++----- github/github_test.go | 3 +-- github/messages.go | 2 +- github/orgs_audit_log_test.go | 1 - github/orgs_members_test.go | 1 - github/orgs_test.go | 1 - github/repos_contents.go | 8 ++++---- github/repos_test.go | 3 +-- 13 files changed, 16 insertions(+), 24 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index afd9675f2f8..db9a4d7117f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,10 +11,10 @@ linters: # - gosec - misspell - nakedret - # - stylecheck + - stylecheck # - unconvert # - unparam - # - whitespace + - whitespace disable: - errcheck - gosimple diff --git a/example/commitpr/main.go b/example/commitpr/main.go index 61a393184cf..f437c84db63 100644 --- a/example/commitpr/main.go +++ b/example/commitpr/main.go @@ -67,11 +67,11 @@ func getRef() (ref *github.Reference, err error) { // We consider that an error means the branch has not been found and needs to // be created. if *commitBranch == *baseBranch { - return nil, errors.New("The commit branch does not exist but `-base-branch` is the same as `-commit-branch`") + return nil, errors.New("the commit branch does not exist but `-base-branch` is the same as `-commit-branch`") } if *baseBranch == "" { - return nil, errors.New("The `-base-branch` should not be set to an empty string when the branch specified by `-commit-branch` does not exists") + return nil, errors.New("the `-base-branch` should not be set to an empty string when the branch specified by `-commit-branch` does not exists") } var baseRef *github.Reference diff --git a/github/actions_workflow_jobs.go b/github/actions_workflow_jobs.go index d756fcd4cb1..86921baeb45 100644 --- a/github/actions_workflow_jobs.go +++ b/github/actions_workflow_jobs.go @@ -147,5 +147,4 @@ func (s *ActionsService) getWorkflowLogsFromURL(ctx context.Context, u string, f resp, err = s.getWorkflowLogsFromURL(ctx, u, false) } return resp, err - } diff --git a/github/actions_workflow_runs_test.go b/github/actions_workflow_runs_test.go index 14274d53929..6803ace0ea6 100644 --- a/github/actions_workflow_runs_test.go +++ b/github/actions_workflow_runs_test.go @@ -295,7 +295,6 @@ func TestActionService_ListRepositoryWorkflowRuns(t *testing.T) { "workflow_runs":[ {"id":298499444,"run_number":301,"created_at":"2020-04-11T11:14:54Z","updated_at":"2020-04-11T11:14:54Z"}, {"id":298499445,"run_number":302,"created_at":"2020-04-11T11:14:54Z","updated_at":"2020-04-11T11:14:54Z"}]}`) - }) opts := &ListWorkflowRunsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}} diff --git a/github/enterprise_audit_log_test.go b/github/enterprise_audit_log_test.go index 9f6f4a856e8..2e91346ebf3 100644 --- a/github/enterprise_audit_log_test.go +++ b/github/enterprise_audit_log_test.go @@ -96,5 +96,4 @@ func TestEnterpriseService_GetAuditLog(t *testing.T) { } return resp, err }) - } diff --git a/github/github.go b/github/github.go index a2727ccf4f3..d4d7a54a7f1 100644 --- a/github/github.go +++ b/github/github.go @@ -708,10 +708,10 @@ func (c *Client) checkRateLimitBeforeDo(req *http.Request, rateLimitCategory rat return nil } -// compareHttpResponse returns whether two http.Response objects are equal or not. +// compareHTTPResponse returns whether two http.Response objects are equal or not. // Currently, only StatusCode is checked. This function is used when implementing the // Is(error) bool interface for the custom error types in this package. -func compareHttpResponse(r1, r2 *http.Response) bool { +func compareHTTPResponse(r1, r2 *http.Response) bool { if r1 == nil && r2 == nil { return true } @@ -761,7 +761,7 @@ func (r *ErrorResponse) Is(target error) bool { } if r.Message != v.Message || (r.DocumentationURL != v.DocumentationURL) || - !compareHttpResponse(r.Response, v.Response) { + !compareHTTPResponse(r.Response, v.Response) { return false } @@ -827,7 +827,7 @@ func (r *RateLimitError) Is(target error) bool { return r.Rate == v.Rate && r.Message == v.Message && - compareHttpResponse(r.Response, v.Response) + compareHTTPResponse(r.Response, v.Response) } // AcceptedError occurs when GitHub returns 202 Accepted response with an @@ -881,7 +881,7 @@ func (r *AbuseRateLimitError) Is(target error) bool { return r.Message == v.Message && r.RetryAfter == v.RetryAfter && - compareHttpResponse(r.Response, v.Response) + compareHTTPResponse(r.Response, v.Response) } // sanitizeURL redacts the client_secret parameter from the URL which may be diff --git a/github/github_test.go b/github/github_test.go index e92dbb66d91..08d2c8ad990 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -1229,7 +1229,7 @@ func TestCompareHttpResponse(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - v := compareHttpResponse(tc.h1, tc.h2) + v := compareHTTPResponse(tc.h1, tc.h2) if tc.expected != v { t.Errorf("Expected %t, got %t for (%#v, %#v)", tc.expected, v, tc.h1, tc.h2) } @@ -2028,7 +2028,6 @@ func TestAddOptions_QueryValues(t *testing.T) { } func TestBareDo_returnsOpenBody(t *testing.T) { - client, mux, _, teardown := setup() defer teardown() diff --git a/github/messages.go b/github/messages.go index 01c8b12c4cb..4a03890c7b9 100644 --- a/github/messages.go +++ b/github/messages.go @@ -192,7 +192,7 @@ func ValidatePayloadFromBody(contentType string, readable io.Reader, signature s payload = []byte(form.Get(payloadFormParam)) default: - return nil, fmt.Errorf("Webhook request has unsupported Content-Type %q", contentType) + return nil, fmt.Errorf("webhook request has unsupported Content-Type %q", contentType) } // Only validate the signature if a secret token exists. This is intended for diff --git a/github/orgs_audit_log_test.go b/github/orgs_audit_log_test.go index 1121ffd2d22..95b0a0cf604 100644 --- a/github/orgs_audit_log_test.go +++ b/github/orgs_audit_log_test.go @@ -110,7 +110,6 @@ func TestOrganizationService_GetAuditLog(t *testing.T) { } return resp, err }) - } func TestGetAuditLogOptions_Marshal(t *testing.T) { diff --git a/github/orgs_members_test.go b/github/orgs_members_test.go index 442ae13e7d4..adc14f5b008 100644 --- a/github/orgs_members_test.go +++ b/github/orgs_members_test.go @@ -655,7 +655,6 @@ func TestOrganizationsService_CreateOrgInvitation(t *testing.T) { } fmt.Fprintln(w, `{"email": "octocat@github.com"}`) - }) ctx := context.Background() diff --git a/github/orgs_test.go b/github/orgs_test.go index fe34a5a02bb..b30c48f1bce 100644 --- a/github/orgs_test.go +++ b/github/orgs_test.go @@ -357,7 +357,6 @@ func TestOrganizationsService_ListInstallations_invalidOrg(t *testing.T) { ctx := context.Background() _, _, err := client.Organizations.ListInstallations(ctx, "%", nil) testURLParseError(t, err) - } func TestOrganizationsService_ListInstallations_withListOptions(t *testing.T) { diff --git a/github/repos_contents.go b/github/repos_contents.go index d88ae74b393..86e11c0a750 100644 --- a/github/repos_contents.go +++ b/github/repos_contents.go @@ -132,7 +132,7 @@ func (s *RepositoriesService) DownloadContents(ctx context.Context, owner, repo, for _, contents := range dirContents { if *contents.Name == filename { if contents.DownloadURL == nil || *contents.DownloadURL == "" { - return nil, resp, fmt.Errorf("No download link found for %s", filepath) + return nil, resp, fmt.Errorf("no download link found for %s", filepath) } dlResp, err := s.client.client.Get(*contents.DownloadURL) if err != nil { @@ -141,7 +141,7 @@ func (s *RepositoriesService) DownloadContents(ctx context.Context, owner, repo, return dlResp.Body, &Response{Response: dlResp}, nil } } - return nil, resp, fmt.Errorf("No file named %s found in %s", filename, dir) + return nil, resp, fmt.Errorf("no file named %s found in %s", filename, dir) } // DownloadContentsWithMeta is identical to DownloadContents but additionally @@ -162,7 +162,7 @@ func (s *RepositoriesService) DownloadContentsWithMeta(ctx context.Context, owne for _, contents := range dirContents { if *contents.Name == filename { if contents.DownloadURL == nil || *contents.DownloadURL == "" { - return nil, contents, resp, fmt.Errorf("No download link found for %s", filepath) + return nil, contents, resp, fmt.Errorf("no download link found for %s", filepath) } dlResp, err := s.client.client.Get(*contents.DownloadURL) if err != nil { @@ -171,7 +171,7 @@ func (s *RepositoriesService) DownloadContentsWithMeta(ctx context.Context, owne return dlResp.Body, contents, &Response{Response: dlResp}, nil } } - return nil, nil, resp, fmt.Errorf("No file named %s found in %s", filename, dir) + return nil, nil, resp, fmt.Errorf("no file named %s found in %s", filename, dir) } // GetContents can return either the metadata and content of a single file diff --git a/github/repos_test.go b/github/repos_test.go index 4bb6be22a56..4c799048abb 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -1090,7 +1090,6 @@ func TestRepositoriesService_GetBranchProtection_noDismissalRestrictions(t *test defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") // TODO: remove custom Accept header when this API fully launches testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) @@ -2319,8 +2318,8 @@ func TestRepositoriesService_Dispatch(t *testing.T) { Baz: false, }, } - for _, tc := range testCases { + for _, tc := range testCases { if tc == nil { input = DispatchRequestOptions{EventType: "go"} } else {