From d99c75a08d4666316f21d3b3215012732bf2c44f Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Fri, 2 Sep 2022 09:05:52 +0200 Subject: [PATCH] chore: update linter (#1708) --- .github/workflows/pr.yml | 2 +- .golangci.toml | 25 ++++++++------------ providers/dns/clouddns/internal/client.go | 2 +- providers/dns/cloudns/internal/client.go | 2 +- providers/dns/digitalocean/client.go | 4 ++-- providers/dns/dreamhost/client.go | 3 ++- providers/dns/dyn/client.go | 6 ++--- providers/dns/gandiv5/client.go | 4 ++-- providers/dns/glesys/client.go | 2 +- providers/dns/joker/internal/dmapi/client.go | 2 +- providers/dns/mydnsjp/client.go | 2 +- providers/dns/mythicbeasts/client.go | 4 ++-- providers/dns/namecheap/client.go | 2 +- providers/dns/otc/client.go | 4 ++-- providers/dns/safedns/internal/client.go | 2 +- providers/dns/vercel/internal/client.go | 4 ++-- 16 files changed, 33 insertions(+), 37 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index e1aaa4ab..5a35a946 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest env: GO_VERSION: 1.19 - GOLANGCI_LINT_VERSION: v1.48.0 + GOLANGCI_LINT_VERSION: v1.49.0 HUGO_VERSION: 0.54.0 CGO_ENABLED: 0 LEGO_E2E_TESTS: CI diff --git a/.golangci.toml b/.golangci.toml index 82d1883e..ebd6838d 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -1,5 +1,5 @@ [run] - deadline = "5m" + timeout = "5m" skip-files = [] [linters-settings] @@ -53,13 +53,16 @@ [linters] enable-all = true disable = [ + "deadcode", # deprecated + "exhaustivestruct", # deprecated + "golint", # deprecated + "ifshort", # deprecated "interfacer", # deprecated "maligned", # deprecated - "scopelint", # deprecated - "golint", # deprecated "nosnakecase", # deprecated - "ifshort", # deprecated - "exhaustivestruct", # deprecated + "scopelint", # deprecated + "structcheck", # deprecated + "varcheck", # deprecated "cyclop", # duplicate of gocyclo "sqlclosecheck", # not relevant (SQL) "rowserrcheck", # not relevant (SQL) @@ -102,7 +105,8 @@ exclude = [ "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked", "exported (type|method|function) (.+) should have comment or be unexported", - "ST1000: at least one file in a package should have a package comment" + "ST1000: at least one file in a package should have a package comment", + "package-comments: should have a package comment", ] [[issues.exclude-rules]] path = "(.+)_test.go" @@ -197,12 +201,3 @@ [[issues.exclude-rules]] path = "providers/dns/sakuracloud/client.go" text = "mu is a global variable" - [[issues.exclude-rules]] - path = "providers/dns/tencentcloud/client.go" - text = "RESOURCENOTFOUND_NODATAOFRECORD contains underscore." - [[issues.exclude-rules]] - path = "providers/dns/ibmcloud/internal/wrapper.go" - text = "Dns_Domain(_ResourceRecord)? contains underscore." - [[issues.exclude-rules]] - path = "providers/dns/rfc2136/" - text = "RR_Header contains underscore." diff --git a/providers/dns/clouddns/internal/client.go b/providers/dns/clouddns/internal/client.go index b4d1154f..7ea6234c 100644 --- a/providers/dns/clouddns/internal/client.go +++ b/providers/dns/clouddns/internal/client.go @@ -230,7 +230,7 @@ func (c *Client) doRequest(req *http.Request) ([]byte, error) { } defer resp.Body.Close() - if resp.StatusCode >= 400 { + if resp.StatusCode >= http.StatusBadRequest { return nil, readError(req, resp) } diff --git a/providers/dns/cloudns/internal/client.go b/providers/dns/cloudns/internal/client.go index e9f89217..d5b6a60e 100644 --- a/providers/dns/cloudns/internal/client.go +++ b/providers/dns/cloudns/internal/client.go @@ -283,7 +283,7 @@ func (c *Client) doRequest(method string, uri *url.URL) (json.RawMessage, error) return nil, errors.New(toUnreadableBodyMessage(req, content)) } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("invalid code (%d), error: %s", resp.StatusCode, content) } diff --git a/providers/dns/digitalocean/client.go b/providers/dns/digitalocean/client.go index d89eb598..82580e78 100644 --- a/providers/dns/digitalocean/client.go +++ b/providers/dns/digitalocean/client.go @@ -49,7 +49,7 @@ func (d *DNSProvider) removeTxtRecord(domain string, recordID int) error { } defer resp.Body.Close() - if resp.StatusCode >= 400 { + if resp.StatusCode >= http.StatusBadRequest { return readError(req, resp) } @@ -80,7 +80,7 @@ func (d *DNSProvider) addTxtRecord(fqdn, value string) (*txtRecordResponse, erro } defer resp.Body.Close() - if resp.StatusCode >= 400 { + if resp.StatusCode >= http.StatusBadRequest { return nil, readError(req, resp) } diff --git a/providers/dns/dreamhost/client.go b/providers/dns/dreamhost/client.go index 801751c8..8ddc4da8 100644 --- a/providers/dns/dreamhost/client.go +++ b/providers/dns/dreamhost/client.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "io" + "net/http" "net/url" "github.com/go-acme/lego/v4/log" @@ -49,7 +50,7 @@ func (d *DNSProvider) updateTxtRecord(u fmt.Stringer) error { } defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return fmt.Errorf("request failed with HTTP status code %d", resp.StatusCode) } diff --git a/providers/dns/dyn/client.go b/providers/dns/dyn/client.go index bf87b654..fecef33c 100644 --- a/providers/dns/dyn/client.go +++ b/providers/dns/dyn/client.go @@ -121,7 +121,7 @@ func (d *DNSProvider) sendRequest(method, resource string, payload interface{}) } defer resp.Body.Close() - if resp.StatusCode >= 500 { + if resp.StatusCode >= http.StatusInternalServerError { return nil, fmt.Errorf("API request failed with HTTP status code %d", resp.StatusCode) } @@ -131,9 +131,9 @@ func (d *DNSProvider) sendRequest(method, resource string, payload interface{}) return nil, err } - if resp.StatusCode >= 400 { + if resp.StatusCode >= http.StatusBadRequest { return nil, fmt.Errorf("API request failed with HTTP status code %d: %s", resp.StatusCode, dynRes.Messages) - } else if resp.StatusCode == 307 { + } else if resp.StatusCode == http.StatusTemporaryRedirect { // TODO add support for HTTP 307 response and long running jobs return nil, errors.New("API request returned HTTP 307. This is currently unsupported") } diff --git a/providers/dns/gandiv5/client.go b/providers/dns/gandiv5/client.go index 106fa08c..4ec3e1b5 100644 --- a/providers/dns/gandiv5/client.go +++ b/providers/dns/gandiv5/client.go @@ -163,11 +163,11 @@ func (d *DNSProvider) do(req *http.Request, v interface{}) error { } func checkResponse(resp *http.Response) error { - if resp.StatusCode == 404 && resp.Request.Method == http.MethodGet { + if resp.StatusCode == http.StatusNotFound && resp.Request.Method == http.MethodGet { return nil } - if resp.StatusCode >= 400 { + if resp.StatusCode >= http.StatusBadRequest { data, err := readBody(resp) if err != nil { return fmt.Errorf("%d [%s] request failed: %w", resp.StatusCode, http.StatusText(resp.StatusCode), err) diff --git a/providers/dns/glesys/client.go b/providers/dns/glesys/client.go index 38fd466d..32207280 100644 --- a/providers/dns/glesys/client.go +++ b/providers/dns/glesys/client.go @@ -80,7 +80,7 @@ func (d *DNSProvider) sendRequest(method, resource string, payload interface{}) } defer resp.Body.Close() - if resp.StatusCode >= 400 { + if resp.StatusCode >= http.StatusBadRequest { return nil, fmt.Errorf("request failed with HTTP status code %d", resp.StatusCode) } diff --git a/providers/dns/joker/internal/dmapi/client.go b/providers/dns/joker/internal/dmapi/client.go index 0f0e636a..1c8b34e9 100644 --- a/providers/dns/joker/internal/dmapi/client.go +++ b/providers/dns/joker/internal/dmapi/client.go @@ -154,7 +154,7 @@ func (c *Client) postRequest(cmd string, data url.Values) (*Response, error) { return nil, err } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("HTTP error %d [%s]: %v", resp.StatusCode, http.StatusText(resp.StatusCode), string(body)) } diff --git a/providers/dns/mydnsjp/client.go b/providers/dns/mydnsjp/client.go index 394ab818..16bfa734 100644 --- a/providers/dns/mydnsjp/client.go +++ b/providers/dns/mydnsjp/client.go @@ -21,7 +21,7 @@ func (d *DNSProvider) doRequest(domain, value, cmd string) error { defer resp.Body.Close() - if resp.StatusCode >= 400 { + if resp.StatusCode >= http.StatusBadRequest { var content []byte content, err = io.ReadAll(resp.Body) if err != nil { diff --git a/providers/dns/mythicbeasts/client.go b/providers/dns/mythicbeasts/client.go index 69d05535..195fb196 100644 --- a/providers/dns/mythicbeasts/client.go +++ b/providers/dns/mythicbeasts/client.go @@ -169,7 +169,7 @@ func (d *DNSProvider) createTXTRecord(zone, leaf, value string) error { return fmt.Errorf("createTXTRecord: %w", err) } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return fmt.Errorf("createTXTRecord: error in API: %d", resp.StatusCode) } @@ -221,7 +221,7 @@ func (d *DNSProvider) removeTXTRecord(zone, leaf, value string) error { return fmt.Errorf("removeTXTRecord: %w", err) } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return fmt.Errorf("removeTXTRecord: error in API: %d", resp.StatusCode) } diff --git a/providers/dns/namecheap/client.go b/providers/dns/namecheap/client.go index f81f8c13..6d62df8b 100644 --- a/providers/dns/namecheap/client.go +++ b/providers/dns/namecheap/client.go @@ -110,7 +110,7 @@ func (d *DNSProvider) do(req *http.Request, out interface{}) error { return err } - if resp.StatusCode >= 400 { + if resp.StatusCode >= http.StatusBadRequest { var body []byte body, err = readBody(resp) if err != nil { diff --git a/providers/dns/otc/client.go b/providers/dns/otc/client.go index 21b5d1c5..6ad4cdfd 100644 --- a/providers/dns/otc/client.go +++ b/providers/dns/otc/client.go @@ -132,7 +132,7 @@ func (d *DNSProvider) loginRequest() error { } defer resp.Body.Close() - if resp.StatusCode >= 400 { + if resp.StatusCode >= http.StatusBadRequest { return fmt.Errorf("OTC API request failed with HTTP status code %d", resp.StatusCode) } @@ -253,7 +253,7 @@ func (d *DNSProvider) sendRequest(method, resource string, payload interface{}) } defer resp.Body.Close() - if resp.StatusCode >= 400 { + if resp.StatusCode >= http.StatusBadRequest { return nil, fmt.Errorf("OTC API request %s failed with HTTP status code %d", url, resp.StatusCode) } diff --git a/providers/dns/safedns/internal/client.go b/providers/dns/safedns/internal/client.go index d34e97fc..2d18b569 100644 --- a/providers/dns/safedns/internal/client.go +++ b/providers/dns/safedns/internal/client.go @@ -94,7 +94,7 @@ func (c *Client) RemoveRecord(zone string, recordID int) error { } defer func() { _ = resp.Body.Close() }() - if resp.StatusCode >= 400 { + if resp.StatusCode >= http.StatusBadRequest { return readError(req, resp) } diff --git a/providers/dns/vercel/internal/client.go b/providers/dns/vercel/internal/client.go index 6ce1687d..da68dcb7 100644 --- a/providers/dns/vercel/internal/client.go +++ b/providers/dns/vercel/internal/client.go @@ -60,7 +60,7 @@ func (c *Client) CreateRecord(zone string, record Record) (*CreateRecordResponse } defer func() { _ = resp.Body.Close() }() - if resp.StatusCode >= 400 { + if resp.StatusCode >= http.StatusBadRequest { return nil, readError(req, resp) } @@ -98,7 +98,7 @@ func (c *Client) DeleteRecord(zone string, recordID string) error { } defer func() { _ = resp.Body.Close() }() - if resp.StatusCode >= 400 { + if resp.StatusCode >= http.StatusBadRequest { return readError(req, resp) }