Skip to content

Commit 43abb80

Browse files
authored
lint: unused parameters / 2 (#4055)
* lint: unused parameters / 2 * lint (print, spacing)
1 parent 316d401 commit 43abb80

File tree

10 files changed

+66
-59
lines changed

10 files changed

+66
-59
lines changed

cmd/crowdsec-cli/clisetup/setup/systemd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func fakeExecCommand(ctx context.Context, command string, args ...string) *exec.
2121
return cmd
2222
}
2323

24-
func TestHelperProcess(t *testing.T) {
24+
func TestHelperProcess(_ *testing.T) {
2525
if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
2626
return
2727
}

cmd/crowdsec/output.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
1616
)
1717

18-
func dedupAlerts(alerts []pipeline.RuntimeAlert) ([]*models.Alert, error) {
18+
func dedupAlerts(alerts []pipeline.RuntimeAlert) []*models.Alert {
1919
var dedupCache []*models.Alert
2020

2121
for idx, alert := range alerts {
@@ -41,16 +41,13 @@ func dedupAlerts(alerts []pipeline.RuntimeAlert) ([]*models.Alert, error) {
4141
log.Tracef("went from %d to %d alerts", len(alerts), len(dedupCache))
4242
}
4343

44-
return dedupCache, nil
44+
return dedupCache
4545
}
4646

4747
func PushAlerts(ctx context.Context, alerts []pipeline.RuntimeAlert, client *apiclient.ApiClient) error {
48-
alertsToPush, err := dedupAlerts(alerts)
49-
if err != nil {
50-
return fmt.Errorf("failed to transform alerts for api: %w", err)
51-
}
48+
alertsToPush := dedupAlerts(alerts)
5249

53-
_, _, err = client.Alerts.Add(ctx, alertsToPush)
50+
_, _, err := client.Alerts.Add(ctx, alertsToPush)
5451
if err != nil {
5552
return fmt.Errorf("failed sending alert to LAPI: %w", err)
5653
}
@@ -116,19 +113,24 @@ func runOutput(ctx context.Context, input chan pipeline.Event, overflow chan pip
116113
if err != nil {
117114
return fmt.Errorf("postoverflow failed: %w", err)
118115
}
119-
log.Printf("%s", *event.Overflow.Alert.Message)
116+
117+
log.Info(*event.Overflow.Alert.Message)
118+
120119
// if the Alert is nil, it's to signal bucket is ready for GC, don't track this
121120
// dump after postoveflow processing to avoid missing whitelist info
122121
if dumpStates && event.Overflow.Alert != nil {
123122
if bucketOverflows == nil {
124123
bucketOverflows = make([]pipeline.Event, 0)
125124
}
125+
126126
bucketOverflows = append(bucketOverflows, event)
127127
}
128+
128129
if event.Overflow.Whitelisted {
129-
log.Printf("[%s] is whitelisted, skip.", *event.Overflow.Alert.Message)
130+
log.Infof("[%s] is whitelisted, skip.", *event.Overflow.Alert.Message)
130131
continue
131132
}
133+
132134
if event.Overflow.Reprocess {
133135
log.Debugf("Overflow being reprocessed.")
134136
select {

pkg/cwhub/hub_test.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ func testHubCfg(t *testing.T) *csconfig.LocalHubCfg {
4242
return &local
4343
}
4444

45-
func testHub(t *testing.T, localCfg *csconfig.LocalHubCfg, indexJSON string) (*Hub, error) {
46-
if localCfg == nil {
47-
localCfg = testHubCfg(t)
48-
}
45+
func testHub(t *testing.T, indexJSON string) (*Hub, error) {
46+
localCfg := testHubCfg(t)
4947

5048
err := os.WriteFile(localCfg.HubIndexFile, []byte(indexJSON), 0o644)
5149
require.NoError(t, err)
@@ -60,47 +58,47 @@ func testHub(t *testing.T, localCfg *csconfig.LocalHubCfg, indexJSON string) (*H
6058

6159
func TestIndexEmpty(t *testing.T) {
6260
// an empty hub is valid, and should not have warnings
63-
hub, err := testHub(t, nil, "{}")
61+
hub, err := testHub(t, "{}")
6462
require.NoError(t, err)
6563
assert.Empty(t, hub.Warnings)
6664
}
6765

6866
func TestIndexJSON(t *testing.T) {
6967
// but it can't be an empty string
70-
hub, err := testHub(t, nil, "")
68+
hub, err := testHub(t, "")
7169
cstest.RequireErrorContains(t, err, "invalid hub index: failed to parse index: unexpected end of JSON input")
7270
assert.NotNil(t, hub)
7371
assert.Empty(t, hub.Warnings)
7472

7573
// it must be valid json
76-
hub, err = testHub(t, nil, "def not json")
74+
hub, err = testHub(t, "def not json")
7775
cstest.RequireErrorContains(t, err, "invalid hub index: failed to parse index: invalid character 'd' looking for beginning of value. Run 'sudo cscli hub update' to download the index again")
7876
assert.NotNil(t, hub)
7977
assert.Empty(t, hub.Warnings)
8078

81-
hub, err = testHub(t, nil, "{")
79+
hub, err = testHub(t, "{")
8280
cstest.RequireErrorContains(t, err, "invalid hub index: failed to parse index: unexpected end of JSON input")
8381
assert.NotNil(t, hub)
8482
assert.Empty(t, hub.Warnings)
8583

8684
// and by json we mean an object
87-
hub, err = testHub(t, nil, "[]")
85+
hub, err = testHub(t, "[]")
8886
cstest.RequireErrorContains(t, err, "invalid hub index: failed to parse index: json: cannot unmarshal array into Go value of type cwhub.HubItems")
8987
assert.NotNil(t, hub)
9088
assert.Empty(t, hub.Warnings)
9189
}
9290

9391
func TestIndexUnknownItemType(t *testing.T) {
9492
// Allow unknown fields in the top level object, likely new item types
95-
hub, err := testHub(t, nil, `{"goodies": {}}`)
93+
hub, err := testHub(t, `{"goodies": {}}`)
9694
require.NoError(t, err)
9795
assert.Empty(t, hub.Warnings)
9896
}
9997

10098
func TestHubUpdate(t *testing.T) {
10199
ctx := t.Context()
102100
// update an empty hub with a index containing a parser.
103-
hub, err := testHub(t, nil, "{}")
101+
hub, err := testHub(t, "{}")
104102
require.NoError(t, err)
105103

106104
index1 := `
@@ -149,7 +147,7 @@ func TestHubUpdate(t *testing.T) {
149147

150148
func TestHubUpdateInvalidTemplate(t *testing.T) {
151149
ctx := t.Context()
152-
hub, err := testHub(t, nil, "{}")
150+
hub, err := testHub(t, "{}")
153151
require.NoError(t, err)
154152

155153
downloader := &Downloader{
@@ -164,7 +162,7 @@ func TestHubUpdateInvalidTemplate(t *testing.T) {
164162

165163
func TestHubUpdateCannotWrite(t *testing.T) {
166164
ctx := t.Context()
167-
hub, err := testHub(t, nil, "{}")
165+
hub, err := testHub(t, "{}")
168166
require.NoError(t, err)
169167

170168
index1 := `
@@ -225,7 +223,7 @@ func TestHubUpdateAfterLoad(t *testing.T) {
225223
}
226224
}
227225
}`
228-
hub, err := testHub(t, nil, index1)
226+
hub, err := testHub(t, index1)
229227
require.NoError(t, err)
230228

231229
index2 := `

pkg/database/alertfilter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func handleSimulatedFilter(filter map[string][]string, predicates *[]predicate.A
2626
}
2727
}
2828

29-
func handleOriginFilter(filter map[string][]string, predicates *[]predicate.Alert) {
29+
func handleOriginFilter(filter map[string][]string) {
3030
if _, ok := filter["origin"]; ok {
3131
filter["include_capi"] = []string{"true"}
3232
}
@@ -193,7 +193,7 @@ func alertPredicatesFromFilter(filter map[string][]string) ([]predicate.Alert, e
193193
// else, return bans that are *contained* by the given value (value is the outer)
194194

195195
handleSimulatedFilter(filter, &predicates)
196-
handleOriginFilter(filter, &predicates)
196+
handleOriginFilter(filter)
197197

198198
for param, value := range filter {
199199
switch param {

pkg/exprhelpers/debugger.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ var opHandlers = map[string]opHandler{
180180
func opBegin(out OpOutput, _ *OpOutput, _ int, _ []string, _ *vm.VM, _ *vm.Program) *OpOutput {
181181
out.CodeDepth += IndentStep
182182
out.BlockStart = true
183+
183184
return &out
184185
}
185186

@@ -340,30 +341,30 @@ func opIn(out OpOutput, _ *OpOutput, _ int, _ []string, vm *vm.VM, _ *vm.Program
340341
stack := vm.Stack
341342
out.Condition = true
342343
out.ConditionIn = true
343-
//seems that we tend to receive stack[1] as a map.
344-
//it is tempting to use reflect to extract keys, but we end up with an array that doesn't match the initial order
345-
//(because of the random order of the map)
344+
// it seems that we tend to receive stack[1] as a map.
345+
// it is tempting to use reflect to extract keys, but we end up with an array that doesn't match the initial order
346+
// (because of the random order of the map)
346347
out.Args = append(out.Args, autoQuote(stack[0]))
347348
out.Args = append(out.Args, autoQuote(stack[1]))
348349

349350
return &out
350351
}
351352

352353
func opContains(out OpOutput, _ *OpOutput, _ int, _ []string, vm *vm.VM, _ *vm.Program) *OpOutput {
353-
// kind OpIn , but reverse
354+
// kind of OpIn, but reverse
354355
stack := vm.Stack
355356
out.Condition = true
356357
out.ConditionContains = true
357-
//seems that we tend to receive stack[1] as a map.
358-
//it is tempting to use reflect to extract keys, but we end up with an array that doesn't match the initial order
359-
//(because of the random order of the map)
358+
// it seems that we tend to receive stack[1] as a map.
359+
// it is tempting to use reflect to extract keys, but we end up with an array that doesn't match the initial order
360+
// (because of the random order of the map)
360361
out.Args = append(out.Args, autoQuote(stack[0]))
361362
out.Args = append(out.Args, autoQuote(stack[1]))
362363

363364
return &out
364365
}
365366

366-
func (erp ExprRuntimeDebug) ipDebug(ip int, vm *vm.VM, program *vm.Program, parts []string, outputs []OpOutput) ([]OpOutput, error) {
367+
func (erp ExprRuntimeDebug) ipDebug(ip int, vm *vm.VM, program *vm.Program, parts []string, outputs []OpOutput) []OpOutput {
367368
IdxOut := len(outputs)
368369
prevIdxOut := 0
369370
currentDepth := 0
@@ -418,7 +419,7 @@ func (erp ExprRuntimeDebug) ipDebug(ip int, vm *vm.VM, program *vm.Program, part
418419
}
419420
}
420421

421-
return outputs, nil
422+
return outputs
422423
}
423424

424425
func (erp ExprRuntimeDebug) ipSeek(ip int) []string {
@@ -475,18 +476,14 @@ func RunWithDebug(program *vm.Program, env any, logger *log.Entry) ([]OpOutput,
475476

476477
go func() {
477478
// We must never return until the execution of the program is done
478-
var err error
479-
480479
erp.Logger.Tracef("[START] ip 0")
481480

482481
ops := erp.ipSeek(0)
483482
if ops == nil {
484483
log.Warningf("error while debugging expr: failed getting ops for ip 0")
485484
}
486485

487-
if outputs, err = erp.ipDebug(0, vm, program, ops, outputs); err != nil {
488-
log.Warningf("error while debugging expr: error while debugging at ip 0")
489-
}
486+
outputs = erp.ipDebug(0, vm, program, ops, outputs)
490487

491488
vm.Step()
492489

@@ -497,9 +494,7 @@ func RunWithDebug(program *vm.Program, env any, logger *log.Entry) ([]OpOutput,
497494
break
498495
}
499496

500-
if outputs, err = erp.ipDebug(ip, vm, program, ops, outputs); err != nil {
501-
log.Warningf("error while debugging expr: error while debugging at ip %d", ip)
502-
}
497+
outputs = erp.ipDebug(ip, vm, program, ops, outputs)
503498

504499
vm.Step()
505500
}

pkg/hubops/datarefresh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewDataRefreshCommand(force bool) *DataRefreshCommand {
3535
return &DataRefreshCommand{Force: force}
3636
}
3737

38-
func (*DataRefreshCommand) Prepare(plan *ActionPlan) (bool, error) {
38+
func (*DataRefreshCommand) Prepare(_ *ActionPlan) (bool, error) {
3939
// we can't prepare much at this point because we don't know which data files yet,
4040
// and items needs to be downloaded/updated
4141
// evertyhing will be done in Run()

pkg/hubops/disable.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ func (c *DisableCommand) Prepare(plan *ActionPlan) (bool, error) {
8585
return true, nil
8686
}
8787

88-
func (c *DisableCommand) Run(ctx context.Context, plan *ActionPlan) error {
88+
func (c *DisableCommand) Run(_ context.Context, plan *ActionPlan) error {
8989
i := c.Item
9090

91-
fmt.Println("disabling " + colorizeItemName(i.FQName()))
91+
fmt.Fprintln(os.Stdout, "disabling " + colorizeItemName(i.FQName()))
9292

9393
if err := RemoveInstallLink(i); err != nil {
9494
return fmt.Errorf("while disabling %s: %w", i.FQName(), err)

pkg/hubops/enable.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ func CreateInstallLink(i *cwhub.Item) error {
7777
return nil
7878
}
7979

80-
func (c *EnableCommand) Run(ctx context.Context, plan *ActionPlan) error {
80+
func (c *EnableCommand) Run(_ context.Context, plan *ActionPlan) error {
8181
i := c.Item
8282

83-
fmt.Println("enabling " + colorizeItemName(i.FQName()))
83+
fmt.Fprintln(os.Stdout, "enabling " + colorizeItemName(i.FQName()))
8484

8585
if !i.State.IsDownloaded() {
8686
// XXX: this a warning?

pkg/hubops/purge.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ func (c *PurgeCommand) Prepare(plan *ActionPlan) (bool, error) {
5050
return true, nil
5151
}
5252

53-
func (c *PurgeCommand) Run(ctx context.Context, plan *ActionPlan) error {
53+
func (c *PurgeCommand) Run(_ context.Context, _ *ActionPlan) error {
5454
i := c.Item
5555

56-
fmt.Println("purging " + colorizeItemName(i.FQName()))
56+
fmt.Fprintln(os.Stdout, "purging " + colorizeItemName(i.FQName()))
5757

5858
if err := os.Remove(i.State.DownloadPath); err != nil {
5959
if os.IsNotExist(err) {

0 commit comments

Comments
 (0)