Skip to content

Commit e0c05d7

Browse files
committed
BUILD/MEDIUM: lint: apply stricter rules for linting
1 parent 805e0d1 commit e0c05d7

File tree

21 files changed

+57
-50
lines changed

21 files changed

+57
-50
lines changed

.golangci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ linters-settings:
55
min-confidence: 0
66
gocyclo:
77
min-complexity: 42
8+
cyclop:
9+
max-complexity: 42
810
maligned:
911
suggest-new: true
1012
dupl:
@@ -56,6 +58,20 @@ linters:
5658
- rowserrcheck #rowserrcheck is disabled because of generics
5759
- sqlclosecheck #rowserrcheck is disabled because of generics
5860
- wastedassign #rowserrcheck is disabled because of generics
61+
- ireturn
62+
- tagliatelle
63+
- noctx
64+
- errorlint
65+
- contextcheck
66+
- godox
67+
- containedctx
68+
- unused
69+
- unparam
70+
- prealloc
71+
- forbidigo
72+
- errcheck
73+
- gocritic
74+
5975

6076
issues:
6177
exclude-rules:
@@ -65,6 +81,9 @@ issues:
6581
- linters:
6682
- gosec
6783
text: "G[501]"
84+
- linters:
85+
- gosec
86+
text: "G[404]"
6887

6988
run:
7089
skip-dirs:

adapters/adapters.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ func RecoverMiddleware(logger *log.Logger) func(h http.Handler) http.Handler {
103103
if strings.HasPrefix(ct, "application/json") {
104104
w.Header().Set("Content-Type", "application/json")
105105
}
106-
// nolint:errcheck
107106
w.Write(errMsg)
108107
}
109108
}()

client-native/cn.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ func ConfigureRuntimeClient(ctx context.Context, confClient configuration.Config
143143
return runtimeClient
144144
}
145145
log.Warningf("Error setting up runtime client with sockets: %v : %s", sockets, err.Error())
146-
147146
}
148147
if err != nil {
149148
log.Warning("Runtime API not configured, not using it: " + err.Error())

cmd/dataplaneapi/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func startServer(cfg *configuration.Configuration) (reload configuration.AtomicB
235235
log.Fatalf("Error running HAProxy Data Plane API: %s", err.Error())
236236
}
237237

238-
defer server.Shutdown() // nolint:errcheck
238+
defer server.Shutdown() //nolint:errcheck
239239

240240
return reload
241241
}

configuration/cluster_sync.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (c *ClusterSync) issueRefreshRequest(url, port, basePath string, nodesPath
147147
json := jsoniter.ConfigCompatibleWithStandardLibrary
148148
bytesRepresentation, _ := json.Marshal(nodeData)
149149

150-
req, err := http.NewRequest("PATCH", url, bytes.NewBuffer(bytesRepresentation))
150+
req, err := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer(bytesRepresentation))
151151
if err != nil {
152152
return fmt.Errorf("error creating new POST request for cluster comunication")
153153
}
@@ -165,7 +165,7 @@ func (c *ClusterSync) issueRefreshRequest(url, port, basePath string, nodesPath
165165
if err != nil {
166166
return err
167167
}
168-
if resp.StatusCode != 202 {
168+
if resp.StatusCode != http.StatusAccepted {
169169
return fmt.Errorf("status code not proper [%d] %s", resp.StatusCode, string(body))
170170
}
171171
var responseData Node
@@ -390,7 +390,7 @@ func (c *ClusterSync) issueJoinRequest(url, port, basePath string, registerPath
390390
return errCfg
391391
}
392392
// write id to file
393-
errFID := renameio.WriteFile(c.cfg.HAProxy.NodeIDFile, []byte(responseData.ID), 0o644) // nolint:gosec
393+
errFID := renameio.WriteFile(c.cfg.HAProxy.NodeIDFile, []byte(responseData.ID), 0o644)
394394
if errFID != nil {
395395
return errFID
396396
}
@@ -506,7 +506,7 @@ func (c *ClusterSync) fetchCert() {
506506
apiNodesPath := c.cfg.Cluster.APINodesPath.Load()
507507
id := c.cfg.Cluster.ID.Load()
508508
url = fmt.Sprintf("%s:%d/%s", url, port, strings.TrimLeft(path.Join(apiBasePath, apiNodesPath, id), "/"))
509-
req, err := http.NewRequest("GET", url, nil)
509+
req, err := http.NewRequest(http.MethodGet, url, nil)
510510
if err != nil {
511511
c.activateFetchCert(err)
512512
break
@@ -525,7 +525,7 @@ func (c *ClusterSync) fetchCert() {
525525
c.activateFetchCert(err)
526526
break
527527
}
528-
if resp.StatusCode != 200 {
528+
if resp.StatusCode != http.StatusOK {
529529
c.activateFetchCert(fmt.Errorf("status code not proper [%d] %s", resp.StatusCode, string(body)))
530530
break
531531
}
@@ -610,7 +610,6 @@ func createHTTPClient() *http.Client {
610610
Transport: &http.Transport{
611611
MaxIdleConnsPerHost: 20,
612612
TLSClientConfig: &tls.Config{
613-
//nolint
614613
InsecureSkipVerify: true, // this is deliberate, might only have self signed certificate
615614
},
616615
},

configuration/configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type HAProxyConfiguration struct {
6565
MasterWorkerMode bool `long:"master-worker-mode" description:"Flag to enable helpers when running within HAProxy" group:"haproxy"`
6666
MaxOpenTransactions int64 `long:"max-open-transactions" description:"Limit for active transaction in pending state" default:"20" group:"transaction"`
6767
ValidateCmd string `long:"validate-cmd" description:"Executes a custom command to perform the HAProxy configuration check" group:"reload"`
68-
DisableInotify bool `long:"disable-inotify" description:"Disables inotify watcher watcher for the configuration file" group:"dataplaneapi"`
68+
DisableInotify bool `long:"disable-inotify" description:"Disables inotify watcher for the configuration file" group:"dataplaneapi"`
6969
PIDFile string `long:"pid-file" description:"Path to file that will dataplaneapi use to write its pid" group:"dataplaneapi" example:"/tmp/dataplane.pid"`
7070
UID int `long:"uid" description:"User id value to set on start" group:"dataplaneapi" example:"1000"`
7171
GID int `long:"gid" description:"Group id value to set on start" group:"dataplaneapi" example:"1000"`

configuration/configuration_storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ type StorageDataplaneAPIConfiguration struct {
169169
LogTargets *dpapilog.Targets `yaml:"log_targets,omitempty" hcl:"log_targets,omitempty"`
170170
}
171171

172-
func copyToConfiguration(cfg *Configuration) {
172+
func copyToConfiguration(cfg *Configuration) { //nolint:cyclop,maintidx
173173
cfgStorage := cfg.storage.Get()
174174
if cfgStorage.Name != nil {
175175
cfg.Name.Store(*cfgStorage.Name)

configuration/file-storage-hcl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (s *StorageHCL) SaveAs(filename string) error {
103103
return err
104104
}
105105

106-
return renameio.WriteFile(filename, hcl, 0o644) //nolint:gosec
106+
return renameio.WriteFile(filename, hcl, 0o644)
107107
}
108108

109109
func (s *StorageHCL) Save() error {

configuration/map_sync.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (ms *MapSync) SyncAll(client client_native.HAProxyClient) {
5050
haproxyOptions := Get().HAProxy
5151

5252
d := time.Duration(haproxyOptions.UpdateMapFilesPeriod)
53-
ticker := time.NewTicker(d * time.Second)
53+
ticker := time.NewTicker(d * time.Second) //nolint:durationcheck
5454

5555
for {
5656
select {
@@ -147,7 +147,7 @@ func equalSomeEntries(fEntries, rEntries models.MapEntries, index ...int) bool {
147147
for i := 0; i < maxRandom; i++ {
148148
rand.Seed(time.Now().UTC().UnixNano())
149149
// There's no need for strong number generation, here, just need for performance
150-
r := rand.Intn(max) // nolint:gosec
150+
r := rand.Intn(max)
151151
if len(index) > 0 {
152152
r = index[0]
153153
}
@@ -174,9 +174,9 @@ func equal(a, b models.MapEntries) bool {
174174
}
175175

176176
// dumpRuntimeEntries dumps runtime entries into map file
177-
// Returns true,nil if succeed, otherwise retuns false,error
177+
// Returns true,nil if succeed, otherwise returns false,error
178178
func dumpRuntimeEntries(file string, me models.MapEntries) (bool, error) {
179-
f, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY|os.O_TRUNC, 0600)
179+
f, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY|os.O_TRUNC, 0o600)
180180
if err != nil {
181181
return false, fmt.Errorf("error opening map file: %s %s", file, err.Error())
182182
}

configuration/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (u *Users) getUsersFromUsersListSection(filename, userlistSection string) e
145145
}
146146
data, err := p.Get(parser.UserList, userlistSection, "user")
147147
if err != nil {
148-
return fmt.Errorf("no users configured in %v, error: %s", filename, err.Error())
148+
return fmt.Errorf("no users configured in %v, error: %w", filename, err)
149149
}
150150

151151
return u.setUser(data, cfg.HAProxy.UserListFile)

0 commit comments

Comments
 (0)