From 635b9ac93d6f1b1d4a832d164934ad75bf5d0149 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Fri, 25 Oct 2019 01:27:40 +0200 Subject: [PATCH] chore: update linter. (#997) --- .golangci.toml | 8 +++++++- .travis.yml | 2 ++ acme/api/internal/sender/sender.go | 1 - acme/api/internal/sender/sender_test.go | 1 - challenge/dns01/dns_challenge_test.go | 3 --- challenge/dns01/nameserver_test.go | 1 - challenge/http01/domain_matcher.go | 2 +- cmd/cmd_renew_test.go | 1 - cmd/zz_gen_cmd_dnshelp.go | 1 - internal/dnsdocs/dns.go.tmpl | 2 +- platform/config/env/env_test.go | 1 - providers/dns/alidns/alidns.go | 17 +++++++++-------- providers/dns/cloudxns/internal/client_test.go | 2 -- providers/dns/conoha/internal/client_test.go | 3 --- providers/dns/dnsimple/dnsimple_test.go | 1 - providers/dns/easydns/easydns_test.go | 2 +- providers/dns/iij/iij_test.go | 1 - providers/dns/joker/client_test.go | 2 -- providers/dns/linodev4/linodev4_test.go | 1 - providers/dns/netcup/internal/client.go | 1 - providers/dns/netcup/internal/client_test.go | 1 - providers/dns/nifcloud/internal/client_test.go | 3 --- providers/dns/otc/mock_test.go | 1 - providers/dns/rackspace/rackspace.go | 1 - providers/dns/selectel/internal/client.go | 4 +--- providers/dns/vscale/internal/client.go | 4 +--- 26 files changed, 23 insertions(+), 44 deletions(-) diff --git a/.golangci.toml b/.golangci.toml index ced70b32..e5821edc 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -29,7 +29,10 @@ "dupl", "prealloc", "scopelint", - "bodyclose", # https://github.com/timakin/bodyclose/pull/14 + "bodyclose", + "wsl", + "stylecheck", + "godox", ] [issues] @@ -112,3 +115,6 @@ [[issues.exclude-rules]] path = "providers/dns/gandi/gandi.go" text = "Function 'Present' is too long" + [[issues.exclude-rules]] + path = "cmd/zz_gen_cmd_dnshelp.go" + linters = ["gocyclo", "funlen"] diff --git a/.travis.yml b/.travis.yml index 3c005133..458e0f7e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -88,3 +88,5 @@ deploy: local_dir: docs/public skip_cleanup: true github_token: ${GITHUB_TOKEN} + on: + condition: $STABLE = true diff --git a/acme/api/internal/sender/sender.go b/acme/api/internal/sender/sender.go index 4c856741..7234e8a9 100644 --- a/acme/api/internal/sender/sender.go +++ b/acme/api/internal/sender/sender.go @@ -120,7 +120,6 @@ func (d *Doer) formatUserAgent() string { func checkError(req *http.Request, resp *http.Response) error { if resp.StatusCode >= http.StatusBadRequest { - body, err := ioutil.ReadAll(resp.Body) if err != nil { return fmt.Errorf("%d :: %s :: %s :: %v", resp.StatusCode, req.Method, req.URL, err) diff --git a/acme/api/internal/sender/sender_test.go b/acme/api/internal/sender/sender_test.go index 0ab02257..1a6d980e 100644 --- a/acme/api/internal/sender/sender_test.go +++ b/acme/api/internal/sender/sender_test.go @@ -44,7 +44,6 @@ func TestDo_UserAgentOnAllHTTPMethod(t *testing.T) { for _, test := range testCases { t.Run(test.method, func(t *testing.T) { - _, err := test.call(ts.URL) require.NoError(t, err) diff --git a/challenge/dns01/dns_challenge_test.go b/challenge/dns01/dns_challenge_test.go index 11e156e2..3b2d1455 100644 --- a/challenge/dns01/dns_challenge_test.go +++ b/challenge/dns01/dns_challenge_test.go @@ -93,7 +93,6 @@ func TestChallenge_PreSolve(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - chlg := NewChallenge(core, test.validate, test.provider, WrapPreCheck(test.preCheck)) authz := acme.Authorization{ @@ -178,7 +177,6 @@ func TestChallenge_Solve(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - var options []ChallengeOption if test.preCheck != nil { options = append(options, WrapPreCheck(test.preCheck)) @@ -266,7 +264,6 @@ func TestChallenge_CleanUp(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - chlg := NewChallenge(core, test.validate, test.provider, WrapPreCheck(test.preCheck)) authz := acme.Authorization{ diff --git a/challenge/dns01/nameserver_test.go b/challenge/dns01/nameserver_test.go index 740cb220..6d36635d 100644 --- a/challenge/dns01/nameserver_test.go +++ b/challenge/dns01/nameserver_test.go @@ -188,7 +188,6 @@ func TestResolveConfServers(t *testing.T) { for _, test := range testCases { t.Run(test.fixture, func(t *testing.T) { - result := getNameservers(test.fixture, test.defaults) sort.Strings(result) diff --git a/challenge/http01/domain_matcher.go b/challenge/http01/domain_matcher.go index a28d175a..9d3fc900 100644 --- a/challenge/http01/domain_matcher.go +++ b/challenge/http01/domain_matcher.go @@ -78,8 +78,8 @@ func (m *forwardedMatcher) matches(r *http.Request, domain string) bool { if err != nil { return false } - if len(fwds) == 0 { + if len(fwds) == 0 { return false } diff --git a/cmd/cmd_renew_test.go b/cmd/cmd_renew_test.go index d040eef3..0ad95264 100644 --- a/cmd/cmd_renew_test.go +++ b/cmd/cmd_renew_test.go @@ -110,7 +110,6 @@ func Test_needRenewal(t *testing.T) { for _, test := range testCases { test := test t.Run(test.desc, func(t *testing.T) { - actual := needRenewal(test.x509Cert, "foo.com", test.days) assert.Equal(t, test.expected, actual) diff --git a/cmd/zz_gen_cmd_dnshelp.go b/cmd/zz_gen_cmd_dnshelp.go index 89e29b57..fa131073 100644 --- a/cmd/zz_gen_cmd_dnshelp.go +++ b/cmd/zz_gen_cmd_dnshelp.go @@ -84,7 +84,6 @@ func displayDNSHelp(name string) error { ew := &errWriter{w: w} switch name { - case "acme-dns": // generated from: providers/dns/acmedns/acmedns.toml ew.writeln(`Configuration for Joohoi's ACME-DNS.`) diff --git a/internal/dnsdocs/dns.go.tmpl b/internal/dnsdocs/dns.go.tmpl index 0e70f329..a9b53586 100644 --- a/internal/dnsdocs/dns.go.tmpl +++ b/internal/dnsdocs/dns.go.tmpl @@ -27,7 +27,7 @@ func displayDNSHelp(name string) error { ew := &errWriter{w: w} switch name { -{{ range $provider := .Providers }} +{{- range $provider := .Providers }} case "{{ $provider.Code }}": // generated from: {{ .GeneratedFrom }} ew.writeln(`Configuration for {{ $provider.Name }}.`) diff --git a/platform/config/env/env_test.go b/platform/config/env/env_test.go index db6aeaf0..c1a188f1 100644 --- a/platform/config/env/env_test.go +++ b/platform/config/env/env_test.go @@ -304,7 +304,6 @@ func TestGetOrFile_ReadsFiles(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - err := os.Unsetenv(varEnvFileName) require.NoError(t, err) err = os.Unsetenv(varEnvName) diff --git a/providers/dns/alidns/alidns.go b/providers/dns/alidns/alidns.go index b008bf63..f7eb5e1b 100644 --- a/providers/dns/alidns/alidns.go +++ b/providers/dns/alidns/alidns.go @@ -95,7 +95,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { func (d *DNSProvider) Present(domain, token, keyAuth string) error { fqdn, value := dns01.GetRecord(domain, keyAuth) - _, zoneName, err := d.getHostedZone(domain) + zoneName, err := d.getHostedZone(domain) if err != nil { return fmt.Errorf("alicloud: %v", err) } @@ -118,7 +118,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return fmt.Errorf("alicloud: %v", err) } - _, _, err = d.getHostedZone(domain) + _, err = d.getHostedZone(domain) if err != nil { return fmt.Errorf("alicloud: %v", err) } @@ -134,7 +134,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return nil } -func (d *DNSProvider) getHostedZone(domain string) (string, string, error) { +func (d *DNSProvider) getHostedZone(domain string) (string, error) { request := alidns.CreateDescribeDomainsRequest() var domains []alidns.Domain @@ -145,7 +145,7 @@ func (d *DNSProvider) getHostedZone(domain string) (string, string, error) { response, err := d.client.DescribeDomains(request) if err != nil { - return "", "", fmt.Errorf("API call failed: %v", err) + return "", fmt.Errorf("API call failed: %v", err) } domains = append(domains, response.Domains.Domain...) @@ -159,7 +159,7 @@ func (d *DNSProvider) getHostedZone(domain string) (string, string, error) { authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain)) if err != nil { - return "", "", err + return "", err } var hostedZone alidns.Domain @@ -170,9 +170,10 @@ func (d *DNSProvider) getHostedZone(domain string) (string, string, error) { } if hostedZone.DomainId == "" { - return "", "", fmt.Errorf("zone %s not found in AliDNS for domain %s", authZone, domain) + return "", fmt.Errorf("zone %s not found in AliDNS for domain %s", authZone, domain) } - return fmt.Sprintf("%v", hostedZone.DomainId), hostedZone.DomainName, nil + + return hostedZone.DomainName, nil } func (d *DNSProvider) newTxtRecord(zone, fqdn, value string) *alidns.AddDomainRecordRequest { @@ -186,7 +187,7 @@ func (d *DNSProvider) newTxtRecord(zone, fqdn, value string) *alidns.AddDomainRe } func (d *DNSProvider) findTxtRecords(domain, fqdn string) ([]alidns.Record, error) { - _, zoneName, err := d.getHostedZone(domain) + zoneName, err := d.getHostedZone(domain) if err != nil { return nil, err } diff --git a/providers/dns/cloudxns/internal/client_test.go b/providers/dns/cloudxns/internal/client_test.go index c9d62096..2036e7b8 100644 --- a/providers/dns/cloudxns/internal/client_test.go +++ b/providers/dns/cloudxns/internal/client_test.go @@ -106,7 +106,6 @@ func TestClientGetDomainInformation(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - server := httptest.NewServer(handlerMock(http.MethodGet, test.response, test.data)) client, _ := NewClient("myKey", "mySecret") @@ -210,7 +209,6 @@ func TestClientFindTxtRecord(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - server := httptest.NewServer(handlerMock(http.MethodGet, test.response, test.txtRecords)) client, _ := NewClient("myKey", "mySecret") diff --git a/providers/dns/conoha/internal/client_test.go b/providers/dns/conoha/internal/client_test.go index 75f2bdb4..899d96c4 100644 --- a/providers/dns/conoha/internal/client_test.go +++ b/providers/dns/conoha/internal/client_test.go @@ -136,7 +136,6 @@ func TestClient_GetDomainID(t *testing.T) { } }) } - } func TestClient_CreateRecord(t *testing.T) { @@ -203,8 +202,6 @@ func TestClient_CreateRecord(t *testing.T) { } else { require.NoError(t, err) } - }) } - } diff --git a/providers/dns/dnsimple/dnsimple_test.go b/providers/dns/dnsimple/dnsimple_test.go index 1a951140..0d52e1f6 100644 --- a/providers/dns/dnsimple/dnsimple_test.go +++ b/providers/dns/dnsimple/dnsimple_test.go @@ -112,7 +112,6 @@ func TestNewDNSProviderConfig(t *testing.T) { if test.baseURL != "" { assert.Equal(t, test.baseURL, p.client.BaseURL) } - } else { require.EqualError(t, err, test.expected) } diff --git a/providers/dns/easydns/easydns_test.go b/providers/dns/easydns/easydns_test.go index 2222fb21..a22c22fd 100644 --- a/providers/dns/easydns/easydns_test.go +++ b/providers/dns/easydns/easydns_test.go @@ -237,7 +237,7 @@ func TestDNSProvider_Cleanup_WhenHttpError_ReturnsError(t *testing.T) { assert.Equal(t, "Basic VE9LRU46U0VDUkVU", r.Header.Get("Authorization"), "Authorization") w.WriteHeader(http.StatusNotAcceptable) - _, err := fmt.Fprintf(w, errorMessage) + _, err := fmt.Fprint(w, errorMessage) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } diff --git a/providers/dns/iij/iij_test.go b/providers/dns/iij/iij_test.go index 43151d32..4f25ce79 100644 --- a/providers/dns/iij/iij_test.go +++ b/providers/dns/iij/iij_test.go @@ -199,7 +199,6 @@ func TestSplitDomain(t *testing.T) { assert.Equal(t, test.expectedZone, zone) }) } - } func TestLivePresent(t *testing.T) { diff --git a/providers/dns/joker/client_test.go b/providers/dns/joker/client_test.go index 13e6ec4b..83d37a26 100644 --- a/providers/dns/joker/client_test.go +++ b/providers/dns/joker/client_test.go @@ -485,7 +485,6 @@ func Test_addTxtEntryToZone(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - zone := addTxtEntryToZone(test.input, "_acme-challenge", "test", 120) assert.Equal(t, zone, test.expected) }) @@ -527,7 +526,6 @@ func Test_fixTxtLines(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - line := fixTxtLines(test.input) assert.Equal(t, line, test.expected) }) diff --git a/providers/dns/linodev4/linodev4_test.go b/providers/dns/linodev4/linodev4_test.go index 42f84bda..77800d33 100644 --- a/providers/dns/linodev4/linodev4_test.go +++ b/providers/dns/linodev4/linodev4_test.go @@ -209,7 +209,6 @@ func TestDNSProvider_Present(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - server := newMockServer(test.mockResponses) defer server.Close() diff --git a/providers/dns/netcup/internal/client.go b/providers/dns/netcup/internal/client.go index 733bfd0b..2cf4c093 100644 --- a/providers/dns/netcup/internal/client.go +++ b/providers/dns/netcup/internal/client.go @@ -226,7 +226,6 @@ func (c *Client) GetDNSRecords(hostname, apiSessionID string) ([]DNSRecord, erro } return responseData.DNSRecords, nil - } // doRequest marshals given body to JSON, send the request to netcup API diff --git a/providers/dns/netcup/internal/client_test.go b/providers/dns/netcup/internal/client_test.go index 5a4ff62b..413ededa 100644 --- a/providers/dns/netcup/internal/client_test.go +++ b/providers/dns/netcup/internal/client_test.go @@ -515,7 +515,6 @@ func TestLiveClientAuth(t *testing.T) { require.NoError(t, err) }) } - } func TestLiveClientGetDnsRecords(t *testing.T) { diff --git a/providers/dns/nifcloud/internal/client_test.go b/providers/dns/nifcloud/internal/client_test.go index b9cec1b1..56f0e059 100644 --- a/providers/dns/nifcloud/internal/client_test.go +++ b/providers/dns/nifcloud/internal/client_test.go @@ -81,7 +81,6 @@ func TestChangeResourceRecordSetsErrors(t *testing.T) { for _, test := range testCases { test := test t.Run(test.desc, func(t *testing.T) { - server := runTestServer(test.responseBody, test.statusCode) defer server.Close() @@ -161,7 +160,6 @@ func TestGetChangeErrors(t *testing.T) { for _, test := range testCases { test := test t.Run(test.desc, func(t *testing.T) { - server := runTestServer(test.responseBody, test.statusCode) defer server.Close() @@ -175,5 +173,4 @@ func TestGetChangeErrors(t *testing.T) { assert.EqualError(t, err, test.expected) }) } - } diff --git a/providers/dns/otc/mock_test.go b/providers/dns/otc/mock_test.go index 31778c01..f683f182 100644 --- a/providers/dns/otc/mock_test.go +++ b/providers/dns/otc/mock_test.go @@ -79,7 +79,6 @@ func (m *DNSServerMock) HandleListZonesSuccessfully() { "id":"123123" }]} `) - }) } diff --git a/providers/dns/rackspace/rackspace.go b/providers/dns/rackspace/rackspace.go index 7adb7565..a37632ba 100644 --- a/providers/dns/rackspace/rackspace.go +++ b/providers/dns/rackspace/rackspace.go @@ -98,7 +98,6 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { token: identity.Access.Token.ID, cloudDNSEndpoint: dnsEndpoint, }, nil - } // Present creates a TXT record to fulfill the dns-01 challenge diff --git a/providers/dns/selectel/internal/client.go b/providers/dns/selectel/internal/client.go index 8457bc4a..fda9404a 100644 --- a/providers/dns/selectel/internal/client.go +++ b/providers/dns/selectel/internal/client.go @@ -180,9 +180,7 @@ func (c *Client) do(req *http.Request, to interface{}) (*http.Response, error) { } func checkResponse(resp *http.Response) error { - if resp.StatusCode >= http.StatusBadRequest && - resp.StatusCode <= http.StatusNetworkAuthenticationRequired { - + if resp.StatusCode >= http.StatusBadRequest && resp.StatusCode <= http.StatusNetworkAuthenticationRequired { if resp.Body == nil { return fmt.Errorf("request failed with status code %d and empty body", resp.StatusCode) } diff --git a/providers/dns/vscale/internal/client.go b/providers/dns/vscale/internal/client.go index 7ce7495e..7e297c1b 100644 --- a/providers/dns/vscale/internal/client.go +++ b/providers/dns/vscale/internal/client.go @@ -180,9 +180,7 @@ func (c *Client) do(req *http.Request, to interface{}) (*http.Response, error) { } func checkResponse(resp *http.Response) error { - if resp.StatusCode >= http.StatusBadRequest && - resp.StatusCode <= http.StatusNetworkAuthenticationRequired { - + if resp.StatusCode >= http.StatusBadRequest && resp.StatusCode <= http.StatusNetworkAuthenticationRequired { if resp.Body == nil { return fmt.Errorf("request failed with status code %d and empty body", resp.StatusCode) }