Skip to content

Commit 3d8ad74

Browse files
committed
lint configuration
1 parent 703f86f commit 3d8ad74

File tree

3 files changed

+169
-3
lines changed

3 files changed

+169
-3
lines changed

.golangci.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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
97+
98+
linters:
99+
enable-all: true
100+
disable:
101+
#
102+
# DEPRECATED by golangi-lint
103+
#
104+
105+
#
106+
# Redundant
107+
#
108+
109+
- cyclop
110+
- tenv
111+
- lll
112+
- funlen
113+
- 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+
158+
issues:
159+
exclude-generated: strict
160+
161+
max-issues-per-linter: 0
162+
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"

cmd/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ import (
2020
log "github.com/sirupsen/logrus"
2121
"golang.org/x/sync/errgroup"
2222

23-
"github.com/crowdsecurity/crowdsec/pkg/models"
2423
csbouncer "github.com/crowdsecurity/go-cs-bouncer"
2524
"github.com/crowdsecurity/go-cs-lib/csstring"
2625
"github.com/crowdsecurity/go-cs-lib/version"
2726

27+
"github.com/crowdsecurity/crowdsec/pkg/models"
28+
2829
"github.com/crowdsecurity/cs-custom-bouncer/pkg/cfg"
2930
"github.com/crowdsecurity/cs-custom-bouncer/pkg/custom"
3031
)

pkg/custom/custom_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ func Test_CustomBouncer_Add(t *testing.T) {
175175
if !reflect.DeepEqual(foundData, tt.expectedLines) {
176176
t.Errorf("expected=%v, found=%v", tt.expectedLines, foundData)
177177
}
178-
179178
})
180179
}
181180
}
@@ -288,7 +287,6 @@ func Test_CustomBouncer_Delete(t *testing.T) {
288287
if !reflect.DeepEqual(foundData, tt.expectedLines) {
289288
t.Errorf("expected=%v, found=%v", tt.expectedLines, foundData)
290289
}
291-
292290
})
293291
}
294292
}

0 commit comments

Comments
 (0)