Skip to content

Commit 5f3770c

Browse files
authored
CI: golangci-lint v2 (#113)
1 parent 13dc683 commit 5f3770c

File tree

4 files changed

+131
-165
lines changed

4 files changed

+131
-165
lines changed

.github/workflows/lint.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ jobs:
1616
security-events: write
1717

1818
steps:
19-
2019
- name: Check out code into the Go module directory
2120
uses: actions/checkout@v4
2221
with:
@@ -37,11 +36,11 @@ jobs:
3736
make build
3837
3938
- name: golangci-lint
40-
uses: golangci/golangci-lint-action@v6
39+
uses: golangci/golangci-lint-action@v7
4140
with:
42-
version: v1.64
43-
args: --issues-exit-code=1 --timeout 10m
44-
only-new-issues: false
41+
version: v2.0
42+
args: --issues-exit-code=1 --timeout 10m
43+
only-new-issues: false
4544

4645
- name: Perform CodeQL Analysis
4746
uses: github/codeql-action/analyze@v3

.golangci.yml

Lines changed: 125 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,134 @@
1-
# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
2-
3-
linters-settings:
4-
gci:
5-
sections:
6-
- standard
7-
- default
8-
- prefix(github.com/crowdsecurity)
9-
- prefix(github.com/crowdsecurity/crowdsec)
10-
- prefix(github.com/crowdsecurity/cs-custom-bouncer)
11-
12-
govet:
13-
enable-all: true
14-
disable:
15-
- fieldalignment
16-
17-
misspell:
18-
locale: US
19-
20-
nlreturn:
21-
block-size: 4
22-
23-
nolintlint:
24-
allow-unused: false # report any unused nolint directives
25-
require-explanation: false # don't require an explanation for nolint directives
26-
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
27-
28-
depguard:
29-
rules:
30-
main:
31-
deny:
32-
- pkg: "github.com/pkg/errors"
33-
desc: "errors.Wrap() is deprecated in favor of fmt.Errorf()"
34-
35-
stylecheck:
36-
checks:
37-
- all
38-
- -ST1003 # should not use underscores in Go names; ...
39-
- -ST1005 # error strings should not be capitalized
40-
- -ST1012 # error var ... should have name of the form ErrFoo
41-
- -ST1016 # methods on the same type should have the same receiver name
42-
- -ST1022 # comment on exported var ... should be of the form ...
43-
44-
revive:
45-
ignore-generated-header: true
46-
severity: error
47-
enable-all-rules: true
48-
rules:
49-
- name: add-constant
50-
disabled: true
51-
- name: cognitive-complexity
52-
disabled: true
53-
- name: comment-spacings
54-
disabled: true
55-
- name: confusing-results
56-
disabled: true
57-
- name: cyclomatic
58-
disabled: true
59-
- name: empty-lines
60-
disabled: true
61-
- name: flag-parameter
62-
disabled: true
63-
- name: function-length
64-
disabled: true
65-
- name: if-return
66-
disabled: true
67-
- name: import-alias-naming
68-
disabled: true
69-
- name: import-shadowing
70-
disabled: true
71-
- name: line-length-limit
72-
disabled: true
73-
- name: nested-structs
74-
disabled: true
75-
- name: var-declaration
76-
disabled: true
77-
- name: exported
78-
disabled: true
79-
- name: unexported-naming
80-
disabled: true
81-
- name: unexported-return
82-
disabled: true
83-
- name: unhandled-error
84-
disabled: true
85-
arguments:
86-
- "fmt.Print"
87-
- "fmt.Printf"
88-
- "fmt.Println"
89-
- name: unused-receiver
90-
disabled: true
91-
- name: function-result-limit
92-
arguments:
93-
- 5
94-
wsl:
95-
# Allow blocks to end with comments
96-
allow-trailing-comment: true
1+
version: "2"
972

983
linters:
99-
enable-all: true
4+
default: all
1005
disable:
101-
#
102-
# DEPRECATED by golangi-lint
103-
#
104-
105-
#
106-
# Redundant
107-
#
108-
6+
- contextcheck
1097
- cyclop
110-
- tenv
111-
- lll
8+
- dupl
9+
- err113
10+
- exhaustruct
11+
- forbidigo
11212
- funlen
13+
- gochecknoglobals
11314
- gocognit
114-
115-
#
116-
# Recommended? (easy)
117-
#
118-
119-
- gosec # (gas): Inspects source code for security problems
120-
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
121-
- wrapcheck # Checks that errors returned from external packages are wrapped
122-
123-
#
124-
# Recommended? (requires some work)
125-
#
126-
127-
- contextcheck # check the function whether use a non-inherited context
128-
- mnd # An analyzer to detect magic numbers.
129-
- unparam # Reports unused function parameters
130-
131-
#
132-
# Formatting only, useful in IDE but should not be forced on CI?
133-
#
134-
135-
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
136-
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
137-
- whitespace # Whitespace is a linter that checks for unnecessary newlines at the start and end of functions, if, for, etc.
138-
- wsl # add or remove empty lines
139-
140-
#
141-
# Well intended, but not ready for this
142-
#
143-
- dupl # Tool for code clone detection
144-
- err113 # Golang linter to check the errors handling expressions
145-
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
146-
- testpackage # linter that makes you use a separate _test package
147-
148-
#
149-
# Too strict / too many false positives (for now?)
150-
#
151-
- exhaustruct # Checks if all structure fields are initialized
152-
- forbidigo # Forbids identifiers
153-
- gochecknoglobals # check that no global variables exist
154-
- goconst # Finds repeated strings that could be replaced by a constant
155-
- tagliatelle # Checks the struct tags.
156-
- varnamelen # checks that the length of a variable's name matches its scope
157-
15+
- goconst
16+
- gosec
17+
- lll
18+
- mnd
19+
- nlreturn
20+
- paralleltest
21+
- tagliatelle
22+
- testpackage
23+
- varnamelen
24+
- whitespace
25+
- wrapcheck
26+
- wsl
27+
settings:
28+
29+
depguard:
30+
rules:
31+
main:
32+
deny:
33+
- pkg: github.com/pkg/errors
34+
desc: errors.Wrap() is deprecated in favor of fmt.Errorf()
35+
govet:
36+
disable:
37+
- fieldalignment
38+
39+
enable-all: true
40+
41+
misspell:
42+
locale: US
43+
44+
nlreturn:
45+
block-size: 4
46+
47+
nolintlint:
48+
require-explanation: false
49+
require-specific: false
50+
allow-unused: false
51+
52+
revive:
53+
severity: error
54+
enable-all-rules: true
55+
rules:
56+
- name: add-constant
57+
disabled: true
58+
- name: cognitive-complexity
59+
disabled: true
60+
- name: comment-spacings
61+
disabled: true
62+
- name: confusing-results
63+
disabled: true
64+
- name: cyclomatic
65+
disabled: true
66+
- name: empty-lines
67+
disabled: true
68+
- name: flag-parameter
69+
disabled: true
70+
- name: function-length
71+
disabled: true
72+
- name: import-shadowing
73+
disabled: true
74+
- name: line-length-limit
75+
disabled: true
76+
- name: nested-structs
77+
disabled: true
78+
- name: var-declaration
79+
disabled: true
80+
- name: exported
81+
disabled: true
82+
- name: unexported-naming
83+
disabled: true
84+
- name: unexported-return
85+
disabled: true
86+
- name: unhandled-error
87+
arguments:
88+
- fmt.Print
89+
- fmt.Printf
90+
- fmt.Println
91+
disabled: true
92+
- name: function-result-limit
93+
arguments:
94+
- 5
95+
staticcheck:
96+
checks:
97+
- all
98+
wsl:
99+
allow-trailing-comment: true
100+
exclusions:
101+
presets:
102+
- comments
103+
- common-false-positives
104+
- legacy
105+
- std-error-handling
106+
rules:
107+
- linters:
108+
- govet
109+
text: 'shadow: declaration of "err" shadows declaration'
110+
paths:
111+
- third_party$
112+
- builtin$
113+
- examples$
158114
issues:
159-
exclude-generated: strict
160-
161115
max-issues-per-linter: 0
162116
max-same-issues: 10
163-
exclude-rules:
164-
# `err` is often shadowed, we may continue to do it
165-
- linters:
166-
- govet
167-
text: "shadow: declaration of \"err\" shadows declaration"
117+
formatters:
118+
enable:
119+
- gci
120+
- gofmt
121+
- goimports
122+
settings:
123+
gci:
124+
sections:
125+
- standard
126+
- default
127+
- prefix(github.com/crowdsecurity)
128+
- prefix(github.com/crowdsecurity/crowdsec)
129+
- prefix(github.com/crowdsecurity/cs-custom-bouncer)
130+
exclusions:
131+
paths:
132+
- third_party$
133+
- builtin$
134+
- examples$

pkg/custom/custom.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (c *CustomBouncer) Delete(decision *models.Decision) error {
118118
return nil
119119
}
120120

121-
func (c *CustomBouncer) ShutDown() error {
121+
func (*CustomBouncer) ShutDown() error {
122122
return nil
123123
}
124124

pkg/custom/custom_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type parsedLine struct {
3434
}
3535

3636
func parseFile(path string) []parsedLine {
37-
dat, err := os.ReadFile(binaryOutputFile)
37+
dat, err := os.ReadFile(path)
3838
parsedLines := make([]parsedLine, 0)
3939
if err != nil {
4040
panic(err)

0 commit comments

Comments
 (0)