From ac0d5d8bd3f22bea1b4fb8f395ca01b641787418 Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Sat, 3 Apr 2021 09:50:23 +0200 Subject: [PATCH] chore: bump golangci-lint from v1.24 to v1.39 Signed-off-by: Yoan Blanc --- .golangci.yml | 4 ++++ GNUmakefile | 2 +- api/api.go | 2 +- api/csi.go | 4 ++-- api/jobs.go | 4 +--- api/nodes.go | 3 +-- api/scaling.go | 4 ++-- api/tasks.go | 10 +++++----- client/fingerprint/env_aws.go | 2 +- client/fingerprint/env_azure.go | 2 +- client/fingerprint/env_gce.go | 2 +- command/agent/testagent.go | 2 +- command/deployment_status.go | 2 +- command/job_validate.go | 2 +- command/operator_debug.go | 2 +- drivers/docker/driver.go | 2 +- drivers/java/utils.go | 2 +- drivers/shared/executor/executor_linux.go | 2 +- e2e/cli/command/test_decoder.go | 2 +- 19 files changed, 28 insertions(+), 27 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 2079dca1a..ea0a9d869 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -57,6 +57,10 @@ linters-settings: list-type: blacklist packages: - github.com/hashicorp/consul/command/flags + gocritic: + disabled-checks: + - commentFormatting + - deprecatedComment issues: exclude: diff --git a/GNUmakefile b/GNUmakefile index 5c6888105..9cb39ad16 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -107,7 +107,7 @@ deps: ## Install build and development dependencies lint-deps: ## Install linter dependencies ## Keep versions in sync with tools/go.mod (see https://github.com/golang/go/issues/30515) @echo "==> Updating linter dependencies..." - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.24.0 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.39.0 go install github.com/client9/misspell/cmd/misspell@v0.3.4 go install github.com/hashicorp/go-hclog/hclogvet@v0.1.3 diff --git a/api/api.go b/api/api.go index 84df7ec37..d2deff274 100644 --- a/api/api.go +++ b/api/api.go @@ -720,7 +720,7 @@ func (c *Client) doRequest(r *request) (time.Duration, *http.Response, error) { } start := time.Now() resp, err := c.httpClient.Do(req) - diff := time.Now().Sub(start) + diff := time.Since(start) // If the response is compressed, we swap the body's reader. if resp != nil && resp.Header != nil { diff --git a/api/csi.go b/api/csi.go index d0ada9b9e..c9b0ea744 100644 --- a/api/csi.go +++ b/api/csi.go @@ -120,7 +120,7 @@ func (v *CSIVolumes) CreateSnapshot(snap *CSISnapshot, w *WriteOptions) ([]*CSIS Snapshots: []*CSISnapshot{snap}, } resp := &CSISnapshotCreateResponse{} - meta, err := v.client.write(fmt.Sprintf("/v1/volumes/snapshot"), req, resp, w) + meta, err := v.client.write("/v1/volumes/snapshot", req, resp, w) return resp.Snapshots, meta, err } @@ -129,7 +129,7 @@ func (v *CSIVolumes) DeleteSnapshot(snap *CSISnapshot, w *WriteOptions) error { req := &CSISnapshotDeleteRequest{ Snapshots: []*CSISnapshot{snap}, } - _, err := v.client.delete(fmt.Sprintf("/v1/volumes/snapshot"), req, w) + _, err := v.client.delete("/v1/volumes/snapshot", req, w) return err } diff --git a/api/jobs.go b/api/jobs.go index 7b4cf18a5..d65544519 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -691,9 +691,7 @@ func (m *Multiregion) Copy() *Multiregion { copyRegion := new(MultiregionRegion) copyRegion.Name = region.Name copyRegion.Count = intToPtr(*region.Count) - for _, dc := range region.Datacenters { - copyRegion.Datacenters = append(copyRegion.Datacenters, dc) - } + copyRegion.Datacenters = append(copyRegion.Datacenters, region.Datacenters...) for k, v := range region.Meta { copyRegion.Meta[k] = v } diff --git a/api/nodes.go b/api/nodes.go index 3d951030e..4c9b8c700 100644 --- a/api/nodes.go +++ b/api/nodes.go @@ -224,8 +224,7 @@ func (n *Nodes) monitorDrainNode(ctx context.Context, nodeID string, } if node.DrainStrategy == nil { - var msg *MonitorMessage - msg = Messagef(MonitorMsgLevelInfo, "Drain complete for node %s", nodeID) + msg := Messagef(MonitorMsgLevelInfo, "Drain complete for node %s", nodeID) select { case nodeCh <- msg: case <-ctx.Done(): diff --git a/api/scaling.go b/api/scaling.go index de889172d..2266c8959 100644 --- a/api/scaling.go +++ b/api/scaling.go @@ -24,9 +24,9 @@ func (s *Scaling) ListPolicies(q *QueryOptions) ([]*ScalingPolicyListStub, *Quer return resp, qm, nil } -func (s *Scaling) GetPolicy(ID string, q *QueryOptions) (*ScalingPolicy, *QueryMeta, error) { +func (s *Scaling) GetPolicy(id string, q *QueryOptions) (*ScalingPolicy, *QueryMeta, error) { var policy ScalingPolicy - qm, err := s.client.query("/v1/scaling/policy/"+ID, &policy, q) + qm, err := s.client.query("/v1/scaling/policy/"+id, &policy, q) if err != nil { return nil, nil, err } diff --git a/api/tasks.go b/api/tasks.go index 9c43df476..b5c6ba119 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -165,12 +165,12 @@ type Affinity struct { Weight *int8 `hcl:"weight,optional"` // Weight applied to nodes that match the affinity. Can be negative } -func NewAffinity(LTarget string, Operand string, RTarget string, Weight int8) *Affinity { +func NewAffinity(lTarget string, operand string, rTarget string, weight int8) *Affinity { return &Affinity{ - LTarget: LTarget, - RTarget: RTarget, - Operand: Operand, - Weight: int8ToPtr(Weight), + LTarget: lTarget, + RTarget: rTarget, + Operand: operand, + Weight: int8ToPtr(weight), } } diff --git a/client/fingerprint/env_aws.go b/client/fingerprint/env_aws.go index 9d77c997d..95af1cf87 100644 --- a/client/fingerprint/env_aws.go +++ b/client/fingerprint/env_aws.go @@ -121,7 +121,7 @@ func (f *EnvAWSFingerprint) Fingerprint(request *FingerprintRequest, response *F } // assume we want blank entries - key := "platform.aws." + strings.Replace(k, "/", ".", -1) + key := "platform.aws." + strings.ReplaceAll(k, "/", ".") if unique { key = structs.UniqueNamespace(key) } diff --git a/client/fingerprint/env_azure.go b/client/fingerprint/env_azure.go index b413f94cc..b440ee906 100644 --- a/client/fingerprint/env_azure.go +++ b/client/fingerprint/env_azure.go @@ -162,7 +162,7 @@ func (f *EnvAzureFingerprint) Fingerprint(request *FingerprintRequest, response } // assume we want blank entries - key := "platform.azure." + strings.Replace(k, "/", ".", -1) + key := "platform.azure." + strings.ReplaceAll(k, "/", ".") if attr.unique { key = structs.UniqueNamespace(key) } diff --git a/client/fingerprint/env_gce.go b/client/fingerprint/env_gce.go index a197f3f5a..3849431b6 100644 --- a/client/fingerprint/env_gce.go +++ b/client/fingerprint/env_gce.go @@ -166,7 +166,7 @@ func (f *EnvGCEFingerprint) Fingerprint(req *FingerprintRequest, resp *Fingerpri } // assume we want blank entries - key := "platform.gce." + strings.Replace(k, "/", ".", -1) + key := "platform.gce." + strings.ReplaceAll(k, "/", ".") if unique { key = structs.UniqueNamespace(key) } diff --git a/command/agent/testagent.go b/command/agent/testagent.go index d9487a429..c40ac4fac 100644 --- a/command/agent/testagent.go +++ b/command/agent/testagent.go @@ -117,7 +117,7 @@ func (a *TestAgent) Start() *TestAgent { if a.Name != "" { name = a.Name + "-agent" } - name = strings.Replace(name, "/", "_", -1) + name = strings.ReplaceAll(name, "/", "_") d, err := ioutil.TempDir(TempDir, name) if err != nil { a.T.Fatalf("Error creating data dir %s: %s", filepath.Join(TempDir, name), err) diff --git a/command/deployment_status.go b/command/deployment_status.go index 7236bb5b7..a04e69ef7 100644 --- a/command/deployment_status.go +++ b/command/deployment_status.go @@ -159,7 +159,7 @@ func getDeployment(client *api.Deployments, dID string) (match *api.Deployment, return d, nil, nil } - dID = strings.Replace(dID, "-", "", -1) + dID = strings.ReplaceAll(dID, "-", "") if len(dID) == 1 { return nil, nil, fmt.Errorf("Identifier must contain at least two characters.") } diff --git a/command/job_validate.go b/command/job_validate.go index 9bd04fa8c..bae381357 100644 --- a/command/job_validate.go +++ b/command/job_validate.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - multierror "github.com/hashicorp/go-multierror" + "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/api" "github.com/hashicorp/nomad/command/agent" flaghelper "github.com/hashicorp/nomad/helper/flags" diff --git a/command/operator_debug.go b/command/operator_debug.go index 78db84572..a66d3ff24 100644 --- a/command/operator_debug.go +++ b/command/operator_debug.go @@ -1018,7 +1018,7 @@ func TarCZF(archive string, src, target string) error { } // remove leading path to the src, so files are relative to the archive - path := strings.Replace(file, src, "", -1) + path := strings.ReplaceAll(file, src, "") if target != "" { path = filepath.Join([]string{target, path}...) } diff --git a/drivers/docker/driver.go b/drivers/docker/driver.go index d4960a33d..0bfede86f 100644 --- a/drivers/docker/driver.go +++ b/drivers/docker/driver.go @@ -1159,7 +1159,7 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T config.Env = task.EnvList() - containerName := fmt.Sprintf("%s-%s", strings.Replace(task.Name, "/", "_", -1), task.AllocID) + containerName := fmt.Sprintf("%s-%s", strings.ReplaceAll(task.Name, "/", "_"), task.AllocID) logger.Debug("setting container name", "container_name", containerName) var networkingConfig *docker.NetworkingConfig diff --git a/drivers/java/utils.go b/drivers/java/utils.go index 1615ea643..87b0aac39 100644 --- a/drivers/java/utils.go +++ b/drivers/java/utils.go @@ -20,7 +20,7 @@ func checkForMacJVM() (ok bool, err error) { cmd.Stderr = &out err = cmd.Run() if err != nil { - err = fmt.Errorf("failed check for macOS jvm: %v, out: %v", err, strings.Replace(strings.Replace(out.String(), "\n", " ", -1), `"`, `\"`, -1)) + err = fmt.Errorf("failed check for macOS jvm: %v, out: %v", err, strings.ReplaceAll(strings.ReplaceAll(out.String(), "\n", " "), `"`, `\"`)) return false, err } return true, nil diff --git a/drivers/shared/executor/executor_linux.go b/drivers/shared/executor/executor_linux.go index ef302caf3..7f749c910 100644 --- a/drivers/shared/executor/executor_linux.go +++ b/drivers/shared/executor/executor_linux.go @@ -73,7 +73,7 @@ func NewExecutorWithIsolation(logger hclog.Logger) Executor { logger.Error("unable to initialize stats", "error", err) } return &LibcontainerExecutor{ - id: strings.Replace(uuid.Generate(), "-", "_", -1), + id: strings.ReplaceAll(uuid.Generate(), "-", "_"), logger: logger, totalCpuStats: stats.NewCpuStats(), userCpuStats: stats.NewCpuStats(), diff --git a/e2e/cli/command/test_decoder.go b/e2e/cli/command/test_decoder.go index c3b178f07..0ae91b5f9 100644 --- a/e2e/cli/command/test_decoder.go +++ b/e2e/cli/command/test_decoder.go @@ -218,7 +218,7 @@ func (r *TestReport) Summary() string { fmt.Fprintf(w, "[%s]\t\t↳\t%s\t (%vs)\n", status, tname, test.Elapsed) if test.Failed { for _, line := range test.Output[2:] { - fmt.Fprintf(w, "\t\t\t%s\n", strings.Replace(strings.TrimSpace(line), "\t", " ", -1)) + fmt.Fprintf(w, "\t\t\t%s\n", strings.ReplaceAll(strings.TrimSpace(line), "\t", " ")) } fmt.Fprintln(w, "\t\t\t----------") }