Skip to content

Commit 13a9780

Browse files
committed
Fix lint problems
Signed-off-by: Stavros Foteinopoulos <stafot@gmail.com>
1 parent fada57d commit 13a9780

62 files changed

Lines changed: 408 additions & 201 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ GOIMPORTS_VER := master
6666
GOIMPORTS_BIN := goimports
6767
GOIMPORTS := $(TOOLS_BIN_DIR)/$(GOIMPORTS_BIN)
6868

69-
GOLANGCILINT_VER := v1.64.5
69+
GOLANGCILINT_VER := v2.0.2
7070
GOLANGCILINT_BIN := golangci-lint
7171
GOLANGCILINT := $(TOOLS_BIN_DIR)/$(GOLANGCILINT_BIN)
7272

@@ -96,12 +96,12 @@ check-style: govet lint goformat goimports
9696
## Runs lint against all packages.
9797
lint: $(GOLANGCILINT)
9898
@echo Running golangci-lint
99-
$(GOLANGCILINT) run
99+
$(GOLANGCILINT) run --config .golangci.yml
100100

101101
## Runs lint against all packages for changes only
102102
lint-changes: $(GOLANGCILINT)
103103
@echo Running golangci-lint over changes only
104-
$(GOLANGCILINT) run -n
104+
$(GOLANGCILINT) run -n --config .golangci.yml
105105

106106
## Runs govet against all packages.
107107
.PHONY: vet

cmd/cloud/clicontext/clicontext.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func WriteContexts(contexts *Contexts) error {
121121
if err != nil {
122122
return err
123123
}
124-
defer file.Close()
124+
defer func() { _ = file.Close() }()
125125

126126
encoder := json.NewEncoder(file)
127127
err = encoder.Encode(contexts)

cmd/cloud/contexts.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
log "github.com/sirupsen/logrus"
56
"reflect"
67

78
"github.com/mattermost/mattermost-cloud/cmd/cloud/clicontext"
@@ -90,7 +91,9 @@ type updateContextFlags struct {
9091
func (f *updateContextFlags) addFlags(command *cobra.Command) {
9192
f.createContextFlags.addFlags(command)
9293
command.Flags().StringVar(&f.Context, "context", "", "Name of the context to update")
93-
command.MarkFlagRequired("context")
94+
if err := command.MarkFlagRequired("context"); err != nil {
95+
log.Fatalf("failed to mark flag required: %v", err)
96+
}
9497
command.Flags().BoolVar(&f.ClearAuth, "clear-auth", false, "Turns off authentication for this context")
9598
command.Flags().BoolVar(&f.ConfirmationRequired, "confirmation-required", false, "Require confirmation for commands run in this context")
9699
}
@@ -244,8 +247,9 @@ func newCmdContextCreate() *cobra.Command {
244247
}
245248

246249
flags.addFlags(cmd)
247-
cmd.MarkFlagRequired("server-url")
248-
250+
if err := cmd.MarkFlagRequired("server-url"); err != nil {
251+
log.Fatalf("failed to mark flag required: %v", err)
252+
}
249253
return cmd
250254
}
251255

@@ -255,7 +259,9 @@ type deleteContextFlags struct {
255259

256260
func (f *deleteContextFlags) addFlags(command *cobra.Command) {
257261
command.Flags().StringVar(&f.contextName, "context", "", "Name of the context to delete")
258-
command.MarkFlagRequired("context")
262+
if err := command.MarkFlagRequired("context"); err != nil {
263+
log.Fatalf("failed to mark flag required: %v", err)
264+
}
259265
}
260266

261267
func newCmdContextDelete() *cobra.Command {

cmd/cloud/installation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func newCmdInstallationUpdateDeletion() *cobra.Command {
309309
client := createClient(command.Context(), flags.clusterFlags)
310310

311311
request := &model.PatchInstallationDeletionRequest{}
312-
if flags.installationDeletionPatchRequestOptionsChanged.futureDeletionTimeChanged {
312+
if flags.futureDeletionTimeChanged {
313313
newExpiryTimeMillis := model.GetMillisAtTime(time.Now().Add(flags.futureDeletionTime))
314314
request.DeletionPendingExpiry = &newExpiryTimeMillis
315315
}

cmd/cloud/installation_flag.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ func (flags *installationUpdateFlags) GetPatchInstallationRequest() (*model.Patc
186186

187187
if flags.allowedIPRangesChanged {
188188
allowedIPRanges := &model.AllowedIPRanges{}
189-
allowedIPRanges.FromJSONString(flags.allowedIPRanges)
189+
_, jsonErr := allowedIPRanges.FromJSONString(flags.allowedIPRanges)
190+
if jsonErr != nil {
191+
return nil, jsonErr
192+
}
190193
allowedIPRanges, err := allowedIPRanges.FromJSONString(flags.allowedIPRanges)
191194
if err != nil {
192195
return nil, err

cmd/cloud/logger_hooks.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ func (hook *ClusterLoggerHook) fileWrite(entry *logrus.Entry, kind string) error
8282
log.Println("failed to open logfile:", path, err)
8383
return err
8484
}
85-
defer fd.Close()
85+
defer func() {
86+
if err := fd.Close(); err != nil {
87+
log.Printf("failed to close fd: %v", err)
88+
}
89+
}()
8690

8791
// use our formatter instead of entry.String()
8892
msg, err := hook.formatter.Format(entry)
@@ -91,7 +95,10 @@ func (hook *ClusterLoggerHook) fileWrite(entry *logrus.Entry, kind string) error
9195
log.Println("failed to generate string for entry:", err)
9296
return err
9397
}
94-
fd.Write(msg)
98+
if _, err := fd.Write(msg); err != nil {
99+
log.Println("failed to write to logfile:", err)
100+
return err
101+
}
95102
return nil
96103
}
97104

cmd/cloud/server.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,11 @@ func executeServerCmd(flags serverFlags) error {
413413
}
414414

415415
standardSupervisor := supervisor.NewScheduler(multiDoer, time.Duration(flags.poll)*time.Second, logger)
416-
defer standardSupervisor.Close()
416+
defer func() {
417+
if err := standardSupervisor.Close(); err != nil {
418+
logrus.WithError(err).Error("failed to close standardSupervisor")
419+
}
420+
}()
417421

418422
if flags.slowPoll == 0 {
419423
logger.WithField("slow-poll", flags.slowPoll).Info("Slow scheduler is disabled")
@@ -422,7 +426,11 @@ func executeServerCmd(flags serverFlags) error {
422426
var slowMultiDoer supervisor.MultiDoer
423427
slowMultiDoer = append(slowMultiDoer, supervisor.NewInstallationDeletionSupervisor(instanceID, flags.installationDeletionPendingTime, flags.installationDeletionMaxUpdating, sqlStore, eventsProducer, logger))
424428
slowSupervisor := supervisor.NewScheduler(slowMultiDoer, time.Duration(flags.slowPoll)*time.Second, logger)
425-
defer slowSupervisor.Close()
429+
defer func() {
430+
if err := slowSupervisor.Close(); err != nil {
431+
logrus.WithError(err).Error("failed to close slowSupervisor")
432+
}
433+
}()
426434
}
427435

428436
metricsRouter := mux.NewRouter()

cmd/provisioner-code-gen/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ func newRootCmd() *cobra.Command {
4343

4444
// Binds all flags as viper values
4545
func bindFlags(cmd *cobra.Command) {
46-
viper.BindPFlags(cmd.PersistentFlags())
47-
viper.BindPFlags(cmd.Flags())
46+
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {
47+
logrus.WithError(err).Fatal("failed to bind persistent flags")
48+
}
49+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
50+
logrus.WithError(err).Fatal("failed to bind command flags")
51+
}
52+
4853
for _, c := range cmd.Commands() {
4954
bindFlags(c)
5055
}

cmd/tools/cloudburst/cloudburst.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ func (b *Blaster) cleanupInstallations(installations map[string]*cloud.Installat
345345
fallthrough
346346
case cloud.InstallationStateDeletionInProgress:
347347
default:
348-
b.client.DeleteInstallation(fetched.ID)
348+
if err := b.client.DeleteInstallation(fetched.ID); err != nil {
349+
log.WithError(err).Error("failed to delete installation")
350+
}
349351
}
350352
}
351353
}

cmd/tools/ctest/test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package main
77
import (
88
"encoding/json"
99
"fmt"
10+
log "github.com/sirupsen/logrus"
1011
"io"
1112
"net/http"
1213

@@ -36,7 +37,11 @@ func runInstallationLifecycleTest(request *model.CreateInstallationRequest, clie
3637
if err != nil {
3738
return errors.Wrap(err, "failed to run enhanced ping test")
3839
}
39-
defer resp.Body.Close()
40+
defer func() {
41+
if err := resp.Body.Close(); err != nil {
42+
log.WithError(err).Error("failed to close resp.Body")
43+
}
44+
}()
4045

4146
if resp.StatusCode != http.StatusOK {
4247
var body []byte

0 commit comments

Comments
 (0)