From db0642099eeacd48a9df1b11707a63c67b421d3b Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Wed, 14 Aug 2024 10:09:31 -0500 Subject: [PATCH] build: update golangci-lint to 1.60.1 (#23807) * build: update golangci-lint to 1.60.1 * ci: update golangci-lint to v1.60.1 Helps with go1.23 compatability. Introduces some breaking changes / newly enforced linter patterns so those are fixed as well. --- .golangci.yml | 34 ++++++++++++-------------------- GNUmakefile | 2 +- client/fingerprint/env_gce.go | 2 +- command/agent/acl_endpoint.go | 8 ++++---- command/agent/agent_endpoint.go | 4 ++-- command/agent/alloc_endpoint.go | 4 ++-- command/agent/job_endpoint.go | 16 +++++++-------- command/agent/search_endpoint.go | 4 ++-- e2e/clientstate/clientstate.go | 2 +- nomad/csi_endpoint.go | 2 +- nomad/job_endpoint.go | 2 +- 11 files changed, 36 insertions(+), 44 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 413de5a48..d08679282 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,7 +3,7 @@ run: # Timeout for analysis. - deadline: 10m + timeout: 10m # Modules download mode (do not modify go.mod) module-download-mode: readonly @@ -11,26 +11,19 @@ run: # Exclude test files tests: false - # which dirs to skip: they won't be analyzed; - # can use regexp here: generated.*, regexp is applied on full path; - # default value is empty list, but next dirs are always skipped independently - # from this option's value: - # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ - skip-dirs: - - ui - - # which files to skip: they will be analyzed, but issues from them - # won't be reported. Default value is empty list, but there is - # no need to include all autogenerated files, we confidently recognize - # autogenerated files. If it's not please let us know. - skip-files: + # Skip ui and generated files + issues: + exclude-files: - ".*\\.generated\\.go$" - ".*bindata_assetfs\\.go$" + skip-dirs: + - ui -# output configuration options +# Output configuration options output: - # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" - format: colored-line-number + formats: + - format: colored-line-number + path: stdout # print lines of code with issue, default is true print-issued-lines: true @@ -45,10 +38,9 @@ linters-settings: # default is false: such cases aren't reported by default. check-type-assertions: false - # [deprecated] comma-separated list of pairs of the form pkg:regex - # the regex is used to ignore names within pkg. (default "fmt:.*"). - # see https://github.com/kisielk/errcheck#the-deprecated-method for details - ignore: fmt:.*,io/ioutil:^Read.* + exclude-functions: + - io.* + - fmt.* # path to a file containing a list of functions to exclude from checking # see https://github.com/kisielk/errcheck#excluding-functions for details diff --git a/GNUmakefile b/GNUmakefile index be38f9ecd..1a5982a00 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -141,7 +141,7 @@ deps: ## Install build and development dependencies .PHONY: lint-deps lint-deps: ## Install linter dependencies @echo "==> Updating linter dependencies..." - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.2 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1 go install github.com/client9/misspell/cmd/misspell@v0.3.4 go install github.com/hashicorp/go-hclog/hclogvet@v0.2.0 diff --git a/client/fingerprint/env_gce.go b/client/fingerprint/env_gce.go index 6707878c2..108fbde93 100644 --- a/client/fingerprint/env_gce.go +++ b/client/fingerprint/env_gce.go @@ -280,7 +280,7 @@ func (f *EnvGCEFingerprint) isGCE() bool { // Query the metadata url for the machine type, to verify we're on GCE machineType, err := f.Get("machine-type", false) if err != nil { - if re, ok := err.(ReqError); !ok || re.StatusCode != 404 { + if re, ok := err.(ReqError); !ok || re.StatusCode != http.StatusNotFound { // If it wasn't a 404 error, print an error message. f.logger.Debug("error querying GCE Metadata URL, skipping") } diff --git a/command/agent/acl_endpoint.go b/command/agent/acl_endpoint.go index 7fff3dc65..ea03afede 100644 --- a/command/agent/acl_endpoint.go +++ b/command/agent/acl_endpoint.go @@ -138,7 +138,7 @@ func (s *HTTPServer) ACLTokensRequest(resp http.ResponseWriter, req *http.Reques func (s *HTTPServer) ACLTokenBootstrap(resp http.ResponseWriter, req *http.Request) (interface{}, error) { // Ensure this is a PUT or POST - if !(req.Method == "PUT" || req.Method == "POST") { + if !(req.Method == http.MethodPut || req.Method == http.MethodPost) { return nil, CodedError(405, ErrInvalidMethod) } @@ -168,7 +168,7 @@ func (s *HTTPServer) ACLTokenSpecificRequest(resp http.ResponseWriter, req *http switch path { case "/v1/acl/token": - if !(req.Method == "PUT" || req.Method == "POST") { + if !(req.Method == http.MethodPut || req.Method == http.MethodPost) { return nil, CodedError(405, ErrInvalidMethod) } return s.aclTokenUpdate(resp, req, "") @@ -290,7 +290,7 @@ func (s *HTTPServer) aclTokenDelete(resp http.ResponseWriter, req *http.Request, func (s *HTTPServer) UpsertOneTimeToken(resp http.ResponseWriter, req *http.Request) (interface{}, error) { // Ensure this is a PUT or POST - if !(req.Method == "PUT" || req.Method == "POST") { + if !(req.Method == http.MethodPut || req.Method == http.MethodPost) { return nil, CodedError(405, ErrInvalidMethod) } @@ -308,7 +308,7 @@ func (s *HTTPServer) UpsertOneTimeToken(resp http.ResponseWriter, req *http.Requ func (s *HTTPServer) ExchangeOneTimeToken(resp http.ResponseWriter, req *http.Request) (interface{}, error) { // Ensure this is a PUT or POST - if !(req.Method == "PUT" || req.Method == "POST") { + if !(req.Method == http.MethodPut || req.Method == http.MethodPost) { return nil, CodedError(405, ErrInvalidMethod) } diff --git a/command/agent/agent_endpoint.go b/command/agent/agent_endpoint.go index fc3259ac4..5d8f20367 100644 --- a/command/agent/agent_endpoint.go +++ b/command/agent/agent_endpoint.go @@ -108,7 +108,7 @@ func (s *HTTPServer) AgentSelfRequest(resp http.ResponseWriter, req *http.Reques } func (s *HTTPServer) AgentJoinRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { - if req.Method != "PUT" && req.Method != "POST" { + if req.Method != http.MethodPut && req.Method != http.MethodPost { return nil, CodedError(405, ErrInvalidMethod) } srv := s.agent.Server() @@ -312,7 +312,7 @@ func (s *HTTPServer) AgentMonitor(resp http.ResponseWriter, req *http.Request) ( } func (s *HTTPServer) AgentForceLeaveRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { - if req.Method != "PUT" && req.Method != "POST" { + if req.Method != http.MethodPut && req.Method != http.MethodPost { return nil, CodedError(405, ErrInvalidMethod) } srv := s.agent.Server() diff --git a/command/agent/alloc_endpoint.go b/command/agent/alloc_endpoint.go index 62f655de0..b7fc9ad89 100644 --- a/command/agent/alloc_endpoint.go +++ b/command/agent/alloc_endpoint.go @@ -143,7 +143,7 @@ func (s *HTTPServer) allocGet(allocID string, resp http.ResponseWriter, req *htt } func (s *HTTPServer) allocStop(allocID string, resp http.ResponseWriter, req *http.Request) (interface{}, error) { - if !(req.Method == "POST" || req.Method == "PUT") { + if !(req.Method == http.MethodPost || req.Method == http.MethodPut) { return nil, CodedError(405, ErrInvalidMethod) } @@ -358,7 +358,7 @@ func (s *HTTPServer) allocGC(allocID string, resp http.ResponseWriter, req *http } func (s *HTTPServer) allocSignal(allocID string, resp http.ResponseWriter, req *http.Request) (interface{}, error) { - if !(req.Method == "POST" || req.Method == "PUT") { + if !(req.Method == http.MethodPost || req.Method == http.MethodPut) { return nil, CodedError(405, ErrInvalidMethod) } diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index 56b650c10..2f7b9f2c2 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -124,7 +124,7 @@ func (s *HTTPServer) JobSpecificRequest(resp http.ResponseWriter, req *http.Requ } func (s *HTTPServer) jobForceEvaluate(resp http.ResponseWriter, req *http.Request, jobID string) (interface{}, error) { - if req.Method != "PUT" && req.Method != "POST" { + if req.Method != http.MethodPut && req.Method != http.MethodPost { return nil, CodedError(405, ErrInvalidMethod) } var args structs.JobEvaluateRequest @@ -159,7 +159,7 @@ func (s *HTTPServer) jobForceEvaluate(resp http.ResponseWriter, req *http.Reques func (s *HTTPServer) jobPlan(resp http.ResponseWriter, req *http.Request, jobName string) (interface{}, error) { - if req.Method != "PUT" && req.Method != "POST" { + if req.Method != http.MethodPut && req.Method != http.MethodPost { return nil, CodedError(405, ErrInvalidMethod) } @@ -195,7 +195,7 @@ func (s *HTTPServer) jobPlan(resp http.ResponseWriter, req *http.Request, func (s *HTTPServer) ValidateJobRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { // Ensure request method is POST or PUT - if !(req.Method == "POST" || req.Method == "PUT") { + if !(req.Method == http.MethodPost || req.Method == http.MethodPut) { return nil, CodedError(405, ErrInvalidMethod) } @@ -227,7 +227,7 @@ func (s *HTTPServer) ValidateJobRequest(resp http.ResponseWriter, req *http.Requ func (s *HTTPServer) periodicForceRequest(resp http.ResponseWriter, req *http.Request, jobName string) (interface{}, error) { - if req.Method != "PUT" && req.Method != "POST" { + if req.Method != http.MethodPut && req.Method != http.MethodPost { return nil, CodedError(405, ErrInvalidMethod) } @@ -646,7 +646,7 @@ func (s *HTTPServer) jobScaleStatus(resp http.ResponseWriter, req *http.Request, func (s *HTTPServer) jobScaleAction(resp http.ResponseWriter, req *http.Request, jobID string) (interface{}, error) { - if req.Method != "PUT" && req.Method != "POST" { + if req.Method != http.MethodPut && req.Method != http.MethodPost { return nil, CodedError(405, ErrInvalidMethod) } @@ -717,7 +717,7 @@ func (s *HTTPServer) jobVersions(resp http.ResponseWriter, req *http.Request, jo func (s *HTTPServer) jobRevert(resp http.ResponseWriter, req *http.Request, jobID string) (interface{}, error) { - if req.Method != "PUT" && req.Method != "POST" { + if req.Method != http.MethodPut && req.Method != http.MethodPost { return nil, CodedError(405, ErrInvalidMethod) } @@ -745,7 +745,7 @@ func (s *HTTPServer) jobRevert(resp http.ResponseWriter, req *http.Request, jobI func (s *HTTPServer) jobStable(resp http.ResponseWriter, req *http.Request, jobID string) (interface{}, error) { - if req.Method != "PUT" && req.Method != "POST" { + if req.Method != http.MethodPut && req.Method != http.MethodPost { return nil, CodedError(405, ErrInvalidMethod) } @@ -793,7 +793,7 @@ func (s *HTTPServer) jobSummaryRequest(resp http.ResponseWriter, req *http.Reque } func (s *HTTPServer) jobDispatchRequest(resp http.ResponseWriter, req *http.Request, jobID string) (interface{}, error) { - if req.Method != "PUT" && req.Method != "POST" { + if req.Method != http.MethodPut && req.Method != http.MethodPost { return nil, CodedError(405, ErrInvalidMethod) } args := structs.JobDispatchRequest{} diff --git a/command/agent/search_endpoint.go b/command/agent/search_endpoint.go index 7f184ba26..33e6e085d 100644 --- a/command/agent/search_endpoint.go +++ b/command/agent/search_endpoint.go @@ -12,7 +12,7 @@ import ( // SearchRequest accepts a prefix and context and returns a list of matching // IDs for that context. func (s *HTTPServer) SearchRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { - if req.Method == "POST" || req.Method == "PUT" { + if req.Method == http.MethodPost || req.Method == http.MethodPut { return s.newSearchRequest(resp, req) } return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod) @@ -39,7 +39,7 @@ func (s *HTTPServer) newSearchRequest(resp http.ResponseWriter, req *http.Reques } func (s *HTTPServer) FuzzySearchRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { - if req.Method == "POST" || req.Method == "PUT" { + if req.Method == http.MethodPost || req.Method == http.MethodPut { return s.newFuzzySearchRequest(resp, req) } return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod) diff --git a/e2e/clientstate/clientstate.go b/e2e/clientstate/clientstate.go index 2cbc16045..312589135 100644 --- a/e2e/clientstate/clientstate.go +++ b/e2e/clientstate/clientstate.go @@ -336,7 +336,7 @@ func (tc *ClientStateTC) TestClientState_KillDuringRestart(f *framework.F) { return false, err } resp.Body.Close() - return resp.StatusCode == 200, fmt.Errorf("%d != 200", resp.StatusCode) + return resp.StatusCode == http.StatusOK, fmt.Errorf("%d != 200", resp.StatusCode) }, func(err error) { f.NoError(err) }) diff --git a/nomad/csi_endpoint.go b/nomad/csi_endpoint.go index aa0ac393d..cb9db0100 100644 --- a/nomad/csi_endpoint.go +++ b/nomad/csi_endpoint.go @@ -357,7 +357,7 @@ func (v *CSIVolume) Register(args *structs.CSIVolumeRegisterRequest, reply *stru *vol = *existingVol - } else if vol.Topologies == nil || len(vol.Topologies) == 0 { + } else if len(vol.Topologies) == 0 { // The topologies for the volume have already been set // when it was created, so for newly register volumes // we accept the user's description of that topology diff --git a/nomad/job_endpoint.go b/nomad/job_endpoint.go index d30fa2b6b..ec5258c73 100644 --- a/nomad/job_endpoint.go +++ b/nomad/job_endpoint.go @@ -2031,7 +2031,7 @@ func (j *Job) Dispatch(args *structs.JobDispatchRequest, reply *structs.JobDispa // Fetch all jobs that match the parameterized job ID prefix iter, err := snap.JobsByIDPrefix(ws, parameterizedJob.Namespace, parameterizedJob.ID, state.SortDefault) if err != nil { - errMsg := "failed to retrieve jobs for idempotency check" + const errMsg = "failed to retrieve jobs for idempotency check" j.logger.Error(errMsg, "error", err) return fmt.Errorf(errMsg) }