Skip to content

Commit d97ac90

Browse files
authored
enable linters: unnecessary-format, unused-receiver (#4001)
* lint: enable revive/unnecessary-format * config usetesting * lint: enable revive/unused-receiver * update complexity metric * windows build * cyclomatic * align struct tags * lint (use-any)
1 parent 58a9f2b commit d97ac90

File tree

36 files changed

+152
-151
lines changed

36 files changed

+152
-151
lines changed

.golangci.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ linters:
206206

207207
maintidx:
208208
# raise this after refactoring
209-
under: 18
209+
under: 20
210210

211211
misspell:
212212
locale: US
@@ -243,7 +243,7 @@ linters:
243243
- name: cyclomatic
244244
arguments:
245245
# lower this after refactoring
246-
- 39
246+
- 37
247247
- name: empty-block
248248
disabled: true
249249
- name: empty-lines
@@ -310,16 +310,12 @@ linters:
310310
- fmt.Printf
311311
- fmt.Println
312312
disabled: true
313-
- name: unnecessary-format
314-
disabled: true
315313
- name: unnecessary-stmt
316314
disabled: true
317315
- name: unsecure-url-scheme
318316
disabled: true
319317
- name: unused-parameter
320318
disabled: true
321-
- name: unused-receiver
322-
disabled: true
323319
- name: use-any
324320
disabled: true
325321
- name: use-waitgroup-go
@@ -336,6 +332,11 @@ linters:
336332
- -QF1003 # could use tagged switch on ...
337333
- -QF1012 # QF1012: Use fmt.Fprintf(...) instead of ...
338334

335+
usetesting:
336+
os-temp-dir: false
337+
context-background: true
338+
context-todo: true
339+
339340
exclusions:
340341
presets:
341342
- comments

cmd/crowdsec-cli/clialert/alerts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (cli *cliAlerts) displayOneAlert(alert *models.Alert, withDetail bool) erro
156156
alertDecisionsTable(color.Output, cfg.Cscli.Color, alert)
157157

158158
if len(alert.Meta) > 0 {
159-
fmt.Fprintf(os.Stdout, "\n - Context :\n")
159+
fmt.Fprintln(os.Stdout, "\n - Context :")
160160
sort.Slice(alert.Meta, func(i, j int) bool {
161161
return alert.Meta[i].Key < alert.Meta[j].Key
162162
})
@@ -183,7 +183,7 @@ func (cli *cliAlerts) displayOneAlert(alert *models.Alert, withDetail bool) erro
183183
}
184184

185185
if withDetail {
186-
fmt.Fprintf(os.Stdout, "\n - Events :\n")
186+
fmt.Fprintln(os.Stdout, "\n - Events :")
187187

188188
for _, event := range alert.Events {
189189
alertEventTable(color.Output, cfg.Cscli.Color, event)

cmd/crowdsec-cli/clilapi/register.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (cli *cliLapi) register(ctx context.Context, apiURL string, outputFile stri
5252
return fmt.Errorf("api client register: %w", err)
5353
}
5454

55-
log.Printf("Successfully registered to Local API (LAPI)")
55+
log.Info("Successfully registered to Local API (LAPI)")
5656

5757
var dumpFile string
5858

cmd/crowdsec-cli/clilapi/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (cli *cliLapi) Status(ctx context.Context, out io.Writer, hub *cwhub.Hub) e
6868
return fmt.Errorf("failed to authenticate to Local API (LAPI): %w", err)
6969
}
7070

71-
fmt.Fprintf(out, "You can successfully interact with Local API (LAPI)\n")
71+
fmt.Fprintln(out, "You can successfully interact with Local API (LAPI)")
7272

7373
return nil
7474
}

cmd/crowdsec-cli/dashboard_unsupported.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func NewCLIDashboard(_ configGetter) *cliDashboard {
1616
return &cliDashboard{}
1717
}
1818

19-
func (cli cliDashboard) NewCommand() *cobra.Command {
19+
func (cliDashboard) NewCommand() *cobra.Command {
2020
cmd := &cobra.Command{
2121
Use: "dashboard",
2222
DisableAutoGenTag: true,

pkg/acquisition/modules/appsec/appsec_runner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type AppsecRunner struct {
3535
appsecAllowlistsClient *allowlists.AppsecAllowlist
3636
}
3737

38-
func (r *AppsecRunner) MergeDedupRules(collections []appsec.AppsecCollection, logger *log.Entry) string {
38+
func (*AppsecRunner) MergeDedupRules(collections []appsec.AppsecCollection, logger *log.Entry) string {
3939
var rulesArr []string
4040
dedupRules := make(map[string]struct{})
4141
discarded := 0
@@ -265,7 +265,7 @@ func (r *AppsecRunner) handleInBandInterrupt(request *appsec.ParsedRequest) {
265265
}
266266

267267
for tag, remediation := range r.AppsecRuntime.RemediationByTag {
268-
if slices.Contains[[]string, string](in.Tags, tag) {
268+
if slices.Contains(in.Tags, tag) {
269269
r.AppsecRuntime.Response.Action = remediation
270270
}
271271
}

pkg/acquisition/modules/file/file.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (f *FileSource) GetMode() string {
261261
}
262262

263263
// SupportedModes returns the supported modes by the acquisition module
264-
func (f *FileSource) SupportedModes() []string {
264+
func (*FileSource) SupportedModes() []string {
265265
return []string{configuration.TAIL_MODE, configuration.CAT_MODE}
266266
}
267267

@@ -291,19 +291,19 @@ func (f *FileSource) OneShotAcquisition(_ context.Context, out chan types.Event,
291291
return nil
292292
}
293293

294-
func (f *FileSource) GetMetrics() []prometheus.Collector {
294+
func (*FileSource) GetMetrics() []prometheus.Collector {
295295
return []prometheus.Collector{metrics.FileDatasourceLinesRead}
296296
}
297297

298-
func (f *FileSource) GetAggregMetrics() []prometheus.Collector {
298+
func (*FileSource) GetAggregMetrics() []prometheus.Collector {
299299
return []prometheus.Collector{metrics.FileDatasourceLinesRead}
300300
}
301301

302-
func (f *FileSource) GetName() string {
302+
func (*FileSource) GetName() string {
303303
return "file"
304304
}
305305

306-
func (f *FileSource) CanRun() error {
306+
func (*FileSource) CanRun() error {
307307
return nil
308308
}
309309

pkg/acquisition/modules/kubernetesaudit/k8s_audit.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ func (ka *KubernetesAuditSource) GetUuid() string {
4343
return ka.config.UniqueId
4444
}
4545

46-
func (ka *KubernetesAuditSource) GetMetrics() []prometheus.Collector {
46+
func (*KubernetesAuditSource) GetMetrics() []prometheus.Collector {
4747
return []prometheus.Collector{metrics.K8SAuditDataSourceEventCount, metrics.K8SAuditDataSourceRequestCount}
4848
}
4949

50-
func (ka *KubernetesAuditSource) GetAggregMetrics() []prometheus.Collector {
50+
func (*KubernetesAuditSource) GetAggregMetrics() []prometheus.Collector {
5151
return []prometheus.Collector{metrics.K8SAuditDataSourceEventCount, metrics.K8SAuditDataSourceRequestCount}
5252
}
5353

@@ -118,7 +118,7 @@ func (ka *KubernetesAuditSource) GetMode() string {
118118
return ka.config.Mode
119119
}
120120

121-
func (ka *KubernetesAuditSource) GetName() string {
121+
func (*KubernetesAuditSource) GetName() string {
122122
return "k8s-audit"
123123
}
124124

@@ -149,11 +149,11 @@ func (ka *KubernetesAuditSource) StreamingAcquisition(ctx context.Context, out c
149149
return nil
150150
}
151151

152-
func (ka *KubernetesAuditSource) CanRun() error {
152+
func (*KubernetesAuditSource) CanRun() error {
153153
return nil
154154
}
155155

156-
func (ka *KubernetesAuditSource) Dump() interface{} {
156+
func (ka *KubernetesAuditSource) Dump() any {
157157
return ka
158158
}
159159

pkg/acquisition/modules/loki/loki.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ type LokiSource struct {
6161
lokiWebsocket string
6262
}
6363

64-
func (l *LokiSource) GetMetrics() []prometheus.Collector {
64+
func (*LokiSource) GetMetrics() []prometheus.Collector {
6565
return []prometheus.Collector{metrics.LokiDataSourceLinesRead}
6666
}
6767

68-
func (l *LokiSource) GetAggregMetrics() []prometheus.Collector {
68+
func (*LokiSource) GetAggregMetrics() []prometheus.Collector {
6969
return []prometheus.Collector{metrics.LokiDataSourceLinesRead}
7070
}
7171

@@ -259,7 +259,7 @@ func (l *LokiSource) GetMode() string {
259259
return l.Config.Mode
260260
}
261261

262-
func (l *LokiSource) GetName() string {
262+
func (*LokiSource) GetName() string {
263263
return "loki"
264264
}
265265

@@ -353,19 +353,19 @@ func (l *LokiSource) StreamingAcquisition(ctx context.Context, out chan types.Ev
353353
return nil
354354
}
355355

356-
func (l *LokiSource) CanRun() error {
356+
func (*LokiSource) CanRun() error {
357357
return nil
358358
}
359359

360360
func (l *LokiSource) GetUuid() string {
361361
return l.Config.UniqueId
362362
}
363363

364-
func (l *LokiSource) Dump() interface{} {
364+
func (l *LokiSource) Dump() any {
365365
return l
366366
}
367367

368368
// SupportedModes returns the supported modes by the acquisition module
369-
func (l *LokiSource) SupportedModes() []string {
369+
func (*LokiSource) SupportedModes() []string {
370370
return []string{configuration.TAIL_MODE, configuration.CAT_MODE}
371371
}

pkg/acquisition/modules/syslog/syslog.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,27 @@ func (s *SyslogSource) GetUuid() string {
4444
return s.config.UniqueId
4545
}
4646

47-
func (s *SyslogSource) GetName() string {
47+
func (*SyslogSource) GetName() string {
4848
return "syslog"
4949
}
5050

5151
func (s *SyslogSource) GetMode() string {
5252
return s.config.Mode
5353
}
5454

55-
func (s *SyslogSource) Dump() interface{} {
55+
func (s *SyslogSource) Dump() any {
5656
return s
5757
}
5858

59-
func (s *SyslogSource) CanRun() error {
59+
func (*SyslogSource) CanRun() error {
6060
return nil
6161
}
6262

63-
func (s *SyslogSource) GetMetrics() []prometheus.Collector {
63+
func (*SyslogSource) GetMetrics() []prometheus.Collector {
6464
return []prometheus.Collector{metrics.SyslogDataSourceLinesReceived, metrics.SyslogDataSourceLinesParsed}
6565
}
6666

67-
func (s *SyslogSource) GetAggregMetrics() []prometheus.Collector {
67+
func (*SyslogSource) GetAggregMetrics() []prometheus.Collector {
6868
return []prometheus.Collector{metrics.SyslogDataSourceLinesReceived, metrics.SyslogDataSourceLinesParsed}
6969
}
7070

0 commit comments

Comments
 (0)