Skip to content

Commit a1aea2c

Browse files
authored
CI: avoid using nolint with revive (#4144)
The "nolinlint" checks are flaky with revive checks, triggering false positives. So we use revive-specific comments or exclusions in .golangci.yml
1 parent 01988e7 commit a1aea2c

File tree

9 files changed

+23
-15
lines changed

9 files changed

+23
-15
lines changed

.golangci.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ linters:
337337
severity: error
338338
enable-all-rules: true
339339
rules:
340+
- name: argument-limit
341+
arguments: [9]
340342
- name: add-constant
341343
disabled: true
342344
- name: cognitive-complexity
@@ -595,6 +597,11 @@ linters:
595597
path: cmd/crowdsec/flags.go
596598
text: 'deep-exit: .*'
597599

600+
- linters:
601+
- revive
602+
path: cmd/crowdsec-cli/clisetup/setup/systemd_test.go
603+
text: 'deep-exit: .*'
604+
598605
- linters:
599606
- gocritic
600607
path: cmd/crowdsec-cli
@@ -615,11 +622,6 @@ linters:
615622
path: pkg/(appsec|acquisition|dumps|alertcontext|leakybucket|exprhelpers)
616623
text: 'rangeValCopy: .*'
617624

618-
- linters:
619-
- revive
620-
path: pkg/logging/configure.go
621-
text: 'argument-limit: .*'
622-
623625
- linters:
624626
- usetesting
625627
path: pkg/apiserver/(.+)_test.go

cmd/crowdsec-cli/clidecision/decisions.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ cscli decisions list --origin lists --scenario list_name
261261
return cmd
262262
}
263263

264-
//nolint:revive // we'll reduce the number of args later
265264
func (cli *cliDecisions) add(ctx context.Context, addIP, addRange, addDuration, addValue, addScope, addReason, addType string, bypassAllowlist bool) error {
266265
alerts := models.AddAlertsRequest{}
267266
origin := types.CscliOrigin

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestHelperProcess(_ *testing.T) {
3838
}
3939

4040
if i >= len(args) {
41-
os.Exit(2) //nolint:revive
41+
os.Exit(2)
4242
}
4343

4444
if args[i] == "systemctl" && i+1 < len(args) {
@@ -54,7 +54,7 @@ func TestHelperProcess(_ *testing.T) {
5454
fmt.Fprint(os.Stdout, "Names="+unit+"\n")
5555
fmt.Fprint(os.Stdout, "StandardOutput=journal\n")
5656
fmt.Fprint(os.Stdout, "StandardError=journal\n")
57-
os.Exit(0) //nolint:revive
57+
os.Exit(0)
5858
case "list-unit-files":
5959
// systemctl list-unit-files --type=service
6060
//nolint:dupword
@@ -64,7 +64,7 @@ apache2.service enabled enabled
6464
apparmor.service enabled enabled
6565
6666
3 unit files listed.`)
67-
os.Exit(0) //nolint:revive
67+
os.Exit(0)
6868
}
6969
}
7070
}

pkg/apiserver/apiserver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ func isBrokenConnection(maybeError any) bool {
8181
}
8282

8383
func recoverFromPanic(c *gin.Context) {
84-
err := recover() //nolint:revive
84+
//revive:disable-next-line:defer
85+
err := recover()
8586
if err == nil {
8687
return
8788
}

pkg/apiserver/middlewares/v1/cache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ func (rc *RevocationCache) purgeExpired() {
5252
}
5353
}
5454

55-
func (rc *RevocationCache) Get(cert *x509.Certificate) (error, bool) { //nolint:revive
55+
//revive:disable-next-line:error-return
56+
func (rc *RevocationCache) Get(cert *x509.Certificate) (error, bool) {
5657
rc.purgeExpired()
5758
key := rc.generateKey(cert)
5859
rc.mu.RLock()

pkg/apiserver/middlewares/v1/tls_auth.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ func (ta *TLSAuth) isExpired(cert *x509.Certificate) bool {
3737
}
3838

3939
// checkRevocationPath checks a single chain against OCSP and CRL
40-
func (ta *TLSAuth) checkRevocationPath(ctx context.Context, chain []*x509.Certificate) (error, bool) { //nolint:revive
40+
//revive:disable-next-line:error-return
41+
func (ta *TLSAuth) checkRevocationPath(ctx context.Context, chain []*x509.Certificate) (error, bool) {
4142
// if we ever fail to check OCSP or CRL, we should not cache the result
4243
couldCheck := true
4344

pkg/csplugin/hclog_adapter.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,5 +234,7 @@ func safeString(str fmt.Stringer) (s string) {
234234
} else {
235235
s = str.String()
236236
}
237-
return //nolint:revive // bare return for the defer
237+
238+
//revive:disable-next-line:bare-return
239+
return // bare return is required for the defer
238240
}

pkg/dumps/parser_dump.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ func (t *tree) displayResults(opts DumpOpts) {
225225
case "update":
226226
detailsDisplay += fmt.Sprintf("\t%s\t\t%s %s evt.%s : %s -> %s\n", presep, sep, change.Type, strings.Join(change.Path, "."), change.From, yellow(change.To))
227227

228-
if change.Path[0] == "Whitelisted" && change.To == true { //nolint:revive
228+
//revive:disable-next-line:bool-literal-in-expr
229+
if change.Path[0] == "Whitelisted" && change.To == true {
229230
whitelisted = true
230231

231232
if whitelistReason == "" {

pkg/leakybucket/overflows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ func NewAlert(leaky *Leaky, queue *pipeline.Queue) (pipeline.RuntimeAlert, error
361361
srcCopy := srcValue
362362
newApiAlert.Source = &srcCopy
363363

364-
if v, ok := leaky.BucketConfig.Labels["remediation"]; ok && v == true { //nolint:revive
364+
//revive:disable-next-line:bool-literal-in-expr
365+
if v, ok := leaky.BucketConfig.Labels["remediation"]; ok && v == true {
365366
newApiAlert.Remediation = true
366367
}
367368

0 commit comments

Comments
 (0)