Skip to content

Commit 53c34fe

Browse files
committed
BUILD/MINOR: golangci-lint: upgrade linter and fix lint issues
1 parent fa01cc9 commit 53c34fe

File tree

8 files changed

+23
-33
lines changed

8 files changed

+23
-33
lines changed

.golangci.yml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
linters-settings:
22
govet:
3-
check-shadowing: true
3+
shadow: true
44
golint:
55
min-confidence: 0
66
gocyclo:
@@ -24,16 +24,13 @@ linters:
2424
disable:
2525
- dupl
2626
- exhaustive
27-
- exhaustivestruct
2827
- funlen
2928
- gci
3029
- gochecknoglobals
3130
- gocognit
3231
- goconst
3332
- gocyclo
3433
- godot
35-
- goerr113
36-
- gomnd
3734
- lll
3835
- nestif
3936
- nlreturn
@@ -43,18 +40,9 @@ linters:
4340
- paralleltest
4441
- testpackage
4542
- varnamelen
46-
- nosnakecase
4743
- exhaustruct
4844
- nonamedreturns
4945
- forcetypeassert
50-
- golint #deprecated
51-
- varcheck #deprecated
52-
- ifshort #deprecated
53-
- structcheck #deprecated
54-
- maligned #deprecated
55-
- scopelint #deprecated
56-
- interfacer #deprecated
57-
- deadcode #deprecated
5846
- rowserrcheck #rowserrcheck is disabled because of generics
5947
- sqlclosecheck #rowserrcheck is disabled because of generics
6048
- wastedassign #rowserrcheck is disabled because of generics
@@ -73,6 +61,10 @@ linters:
7361
- gocritic
7462
- tagalign
7563
- depguard
64+
- mnd
65+
- err113
66+
- tenv # deprecated
67+
- recvcheck
7668

7769
issues:
7870
exclude:

client-native/cn.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ func ConfigureRuntimeClient(ctx context.Context, confClient configuration.Config
125125
// else try to find process specific sockets and set them up
126126
sockets := make(map[int]string)
127127
for _, r := range runtimeAPIs {
128-
//nolint:govet
129128
if misc.IsUnixSocketAddr(*r.Address) && r.Process != "" {
130129
process, err := strconv.ParseInt(r.Process, 10, 64)
131130
if err == nil {

configuration/map_sync.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,29 +124,29 @@ func equalSomeEntries(fEntries, rEntries models.MapEntries, index ...int) bool {
124124
return false
125125
}
126126

127-
max := 0
127+
maxNo := 0
128128
switch l := len(rEntries); {
129129
case l > 19:
130130
for i := l - 20; i < l; i++ {
131131
if rEntries[i].Key != fEntries[i].Key || rEntries[i].Value != fEntries[i].Value {
132132
return false
133133
}
134134
}
135-
max = l - 19
135+
maxNo = l - 19
136136
case l == 0:
137137
return true
138138
default:
139-
max = l
139+
maxNo = l
140140
}
141141

142142
maxRandom := 10
143-
if max < 10 {
144-
maxRandom = max
143+
if maxNo < 10 {
144+
maxRandom = maxNo
145145
}
146146

147147
for range maxRandom {
148148
// There's no need for strong number generation, here, just need for performance
149-
r := rand.Intn(max)
149+
r := rand.Intn(maxNo)
150150
if len(index) > 0 {
151151
r = index[0]
152152
}

configuration/user.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,20 @@ func AuthenticateUser(user string, pass string) (interface{}, error) {
176176
if strings.HasPrefix(u.Password, "\"${") && strings.HasSuffix(u.Password, "}\"") {
177177
userPass = os.Getenv(misc.ExtractEnvVar(userPass))
178178
if userPass == "" {
179-
return nil, api_errors.New(401, fmt.Sprintf("%s %s", "can not read password from env variable:", u.Password))
179+
return nil, api_errors.New(401, "%s %s", "can not read password from env variable:", u.Password)
180180
}
181181
}
182182

183183
if u.IsInsecure {
184184
if pass == userPass {
185185
return user, nil
186186
}
187-
return nil, api_errors.New(401, fmt.Sprintf("%s %s", "invalid password:", pass))
187+
return nil, api_errors.New(401, "%s %s", "invalid password:", pass)
188188
}
189189
if checkPassword(pass, userPass) {
190190
return user, nil
191191
}
192-
return nil, api_errors.New(401, fmt.Sprintf("%s %s", "invalid password:", pass))
192+
return nil, api_errors.New(401, "%s %s", "invalid password:", pass)
193193
}
194194

195195
func checkPassword(pass, storedPass string) bool {

configure_data_plane.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
704704
data.ID = service_discovery.NewServiceDiscoveryUUID()
705705
}
706706
if errSD = service_discovery.ValidateConsulData(data, true); errSD != nil {
707-
log.Fatalf("Error validating Consul instance: " + errSD.Error())
707+
log.Fatal("Error validating Consul instance: " + errSD.Error())
708708
}
709709
if errSD = discovery.AddNode("consul", *data.ID, data); errSD != nil {
710710
log.Warning("Error creating consul instance: " + errSD.Error())
@@ -720,7 +720,7 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
720720
data.ID = service_discovery.NewServiceDiscoveryUUID()
721721
}
722722
if errSD = service_discovery.ValidateAWSData(data, true); errSD != nil {
723-
log.Fatalf("Error validating AWS instance: " + errSD.Error())
723+
log.Fatal("Error validating AWS instance: " + errSD.Error())
724724
}
725725
if errSD = discovery.AddNode("aws", *data.ID, data); errSD != nil {
726726
log.Warning("Error creating AWS instance: " + errSD.Error())
@@ -1057,10 +1057,10 @@ func handleSignals(ctx context.Context, cancel context.CancelFunc, sigs chan os.
10571057
func reloadConfigurationFile(client client_native.HAProxyClient, haproxyOptions dataplaneapi_config.HAProxyConfiguration, users *dataplaneapi_config.Users) {
10581058
confClient, err := cn.ConfigureConfigurationClient(haproxyOptions, mWorker)
10591059
if err != nil {
1060-
log.Fatalf(err.Error())
1060+
log.Fatal(err.Error())
10611061
}
10621062
if err := users.Init(); err != nil {
1063-
log.Fatalf(err.Error())
1063+
log.Fatal(err.Error())
10641064
}
10651065
log.Info("Rereading Configuration Files")
10661066
clientMutex.Lock()

discovery/consul_service_discovery_instance.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (c *consulInstance) validateHealthChecks(node *serviceEntry) bool {
211211
}
212212

213213
func (c *consulInstance) validateHealthChecksAny(node *serviceEntry) bool {
214-
if node.Checks == nil || len(node.Checks) == 0 {
214+
if len(node.Checks) == 0 {
215215
return false
216216
}
217217

@@ -224,7 +224,7 @@ func (c *consulInstance) validateHealthChecksAny(node *serviceEntry) bool {
224224
}
225225

226226
func (c *consulInstance) validateHealthChecksAll(node *serviceEntry) bool {
227-
if node.Checks == nil || len(node.Checks) == 0 {
227+
if len(node.Checks) == 0 {
228228
return false
229229
}
230230

@@ -237,7 +237,7 @@ func (c *consulInstance) validateHealthChecksAll(node *serviceEntry) bool {
237237
}
238238

239239
func (c *consulInstance) validateHealthChecksMin(node *serviceEntry) bool {
240-
if node.Checks == nil || len(node.Checks) == 0 {
240+
if len(node.Checks) == 0 {
241241
return false
242242
}
243243

handlers/information.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ func (h *GetInfoHandlerImpl) Handle(params information.GetInfoParams, principal
9797
sys.MemInfo.TotalMemory = int64(mem.Total)
9898
sys.MemInfo.FreeMemory = int64(mem.Free)
9999
}
100-
//nolint:govet
101100
if uptime, err := host.Uptime(); err == nil {
102101
uptimeInt64 := int64(uptime)
103102
sys.Uptime = &uptimeInt64

haproxy/reload_agent_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
)
2727

2828
func TestReloadAgentDoesntMissReloads(t *testing.T) {
29-
ctx, cancel := context.WithCancel(context.Background())
30-
f, err := os.CreateTemp("", "config.cfg")
29+
ctx, cancel := context.WithCancel(t.Context())
30+
f, err := os.CreateTemp(t.TempDir(), "config.cfg")
3131
require.NoError(t, err)
3232
assert.NotNil(t, f)
3333
t.Cleanup(func() {

0 commit comments

Comments
 (0)