Skip to content

Commit 57668a6

Browse files
authored
lint: update configuration, reserve fmt.Print for debugging (#402)
1 parent 75194e8 commit 57668a6

File tree

13 files changed

+73
-90
lines changed

13 files changed

+73
-90
lines changed

.golangci.yml

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,22 @@ version: "2"
33
linters:
44
default: all
55
disable:
6-
- cyclop
6+
- cyclop # revive
7+
- funlen # revive
8+
- gocognit # revive
9+
- gocyclo # revive
10+
- lll # revive
11+
712
- dupl
813
- err113
914
- exhaustruct
10-
- forbidigo
11-
- funlen
1215
- gochecknoglobals
13-
- gocognit
1416
- goconst
15-
- gocritic
16-
- gocyclo
1717
- godox
1818
- gosec
1919
- ireturn
20-
- lll
2120
- maintidx
2221
- mnd
23-
- nestif
2422
- nlreturn
2523
- paralleltest
2624
- tagliatelle
@@ -38,15 +36,31 @@ linters:
3836
deny:
3937
- pkg: github.com/pkg/errors
4038
desc: errors.Wrap() is deprecated in favor of fmt.Errorf()
39+
40+
errcheck:
41+
check-type-assertions: false
42+
43+
gocritic:
44+
enable-all: true
45+
disabled-checks:
46+
- appendCombine
47+
- commentFormatting
48+
- paramTypeCombine
49+
- sloppyReassign
50+
- unnamedResult
51+
4152
govet:
4253
disable:
4354
- fieldalignment
44-
- shadow
4555
enable-all: true
4656

4757
misspell:
4858
locale: US
4959

60+
nestif:
61+
# lower this after refactoring
62+
min-complexity: 13
63+
5064
nlreturn:
5165
block-size: 4
5266

@@ -68,15 +82,15 @@ linters:
6882
- name: confusing-results
6983
disabled: true
7084
- name: cyclomatic
71-
disabled: true
85+
arguments:
86+
# lower this after refactoring
87+
- 28
7288
- name: empty-lines
7389
disabled: true
7490
- name: flag-parameter
7591
disabled: true
7692
- name: function-length
7793
disabled: true
78-
- name: if-return
79-
disabled: true
8094
- name: import-alias-naming
8195
disabled: true
8296
- name: import-shadowing
@@ -85,34 +99,20 @@ linters:
8599
disabled: true
86100
- name: nested-structs
87101
disabled: true
88-
- name: redundant-build-tag
89-
disabled: true
90-
- name: var-declaration
91-
disabled: true
92102
- name: exported
93103
disabled: true
94-
- name: unexported-naming
95-
disabled: true
96104
- name: unexported-return
97105
disabled: true
98106
- name: unhandled-error
99107
arguments:
100108
- fmt.Print
101109
- fmt.Printf
102110
- fmt.Println
103-
disabled: true
104-
- name: unused-receiver
105-
disabled: true
106111
- name: function-result-limit
107112
arguments:
108113
- 5
109114
staticcheck:
110115
checks:
111-
- -ST1003
112-
- -ST1005
113-
- -ST1012
114-
- -ST1016
115-
- -ST1022
116116
- all
117117
wsl:
118118
allow-trailing-comment: true
@@ -124,8 +124,9 @@ linters:
124124
- std-error-handling
125125
rules:
126126
- linters:
127-
- errcheck
128-
text: Error return value of `.*` is not checked
127+
- govet
128+
text: 'shadow: declaration of "(err|ctx)" shadows declaration'
129+
129130
- linters:
130131
- perfsprint
131132
text: fmt.Sprintf can be replaced .*

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func Execute() error {
147147
flag.Parse()
148148

149149
if *bouncerVersion {
150-
fmt.Print(version.FullString())
150+
fmt.Fprint(os.Stdout, version.FullString())
151151
return nil
152152
}
153153

@@ -161,7 +161,7 @@ func Execute() error {
161161
}
162162

163163
if *showConfig {
164-
fmt.Println(string(configMerged))
164+
fmt.Fprintln(os.Stdout, string(configMerged))
165165
return nil
166166
}
167167

pkg/dryrun/dryrun.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@ func NewDryRun(_ *cfg.BouncerConfig) (types.Backend, error) {
1616
return &dryRun{}, nil
1717
}
1818

19-
func (d *dryRun) Init() error {
19+
func (*dryRun) Init() error {
2020
log.Infof("backend.Init() called")
2121
return nil
2222
}
2323

24-
func (d *dryRun) Commit() error {
24+
func (*dryRun) Commit() error {
2525
log.Infof("backend.Commit() called")
2626
return nil
2727
}
2828

29-
func (d *dryRun) Add(decision *models.Decision) error {
29+
func (*dryRun) Add(decision *models.Decision) error {
3030
log.Infof("backend.Add() called with %s", *decision.Value)
3131
return nil
3232
}
3333

34-
func (d *dryRun) CollectMetrics() {
34+
func (*dryRun) CollectMetrics() {
3535
log.Infof("backend.CollectMetrics() called")
3636
}
3737

38-
func (d *dryRun) Delete(decision *models.Decision) error {
38+
func (*dryRun) Delete(decision *models.Decision) error {
3939
log.Infof("backend.Delete() called with %s", *decision.Value)
4040
return nil
4141
}
4242

43-
func (d *dryRun) ShutDown() error {
43+
func (*dryRun) ShutDown() error {
4444
log.Infof("backend.ShutDown() called")
4545
return nil
4646
}

pkg/ipsetcmd/ipset.go

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,21 @@ func (i *IPSet) Len() int {
213213
}
214214

215215
for _, line := range strings.Split(string(out), "\n") {
216-
if strings.Contains(strings.ToLower(line), "number of entries:") {
217-
fields := strings.Split(line, ":")
218-
if len(fields) != 2 {
219-
continue
220-
}
221-
count, err := strconv.Atoi(strings.TrimSpace(fields[1]))
222-
if err != nil {
223-
return 0
224-
}
225-
return count
216+
if !strings.Contains(strings.ToLower(line), "number of entries:") {
217+
continue
226218
}
219+
220+
fields := strings.Split(line, ":")
221+
if len(fields) != 2 {
222+
continue
223+
}
224+
225+
count, err := strconv.Atoi(strings.TrimSpace(fields[1]))
226+
if err != nil {
227+
return 0
228+
}
229+
230+
return count
227231
}
228232

229233
return 0
@@ -242,17 +246,21 @@ func GetSetsStartingWith(name string) (map[string]*IPSet, error) {
242246
sets := make(map[string]*IPSet, 0)
243247

244248
for _, line := range strings.Split(string(out), "\n") {
245-
if strings.HasPrefix(line, name) {
246-
fields := strings.Fields(line)
247-
if len(fields) != 1 {
248-
continue
249-
}
250-
set, err := NewIPSet(fields[0])
251-
if err != nil {
252-
return nil, err
253-
}
254-
sets[fields[0]] = set
249+
if !strings.HasPrefix(line, name) {
250+
continue
255251
}
252+
253+
fields := strings.Fields(line)
254+
if len(fields) != 1 {
255+
continue
256+
}
257+
258+
set, err := NewIPSet(fields[0])
259+
if err != nil {
260+
return nil, err
261+
}
262+
263+
sets[fields[0]] = set
256264
}
257265

258266
return sets, nil

pkg/iptables/iptables.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux
2-
// +build linux
32

43
package iptables
54

pkg/iptables/iptables_context.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux
2-
// +build linux
32

43
package iptables
54

pkg/iptables/metrics.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux
2-
// +build linux
32

43
package iptables
54

pkg/metrics/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (m metricMap) MustRegisterAll() {
5050
}
5151
}
5252

53-
var Map metricMap = metricMap{
53+
var Map = metricMap{
5454
ActiveBannedIPs: {
5555
Name: "active_decisions",
5656
Unit: "ip",

pkg/nftables/metrics.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux
2-
// +build linux
32

43
package nftables
54

pkg/nftables/nftables.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux
2-
// +build linux
32

43
package nftables
54

@@ -236,11 +235,7 @@ func (n *nft) commitAddedDecisions() error {
236235
return err
237236
}
238237

239-
if err := n.v6.addElements(ip6); err != nil {
240-
return err
241-
}
242-
243-
return nil
238+
return n.v6.addElements(ip6)
244239
}
245240

246241
func (n *nft) Commit() error {
@@ -250,11 +245,7 @@ func (n *nft) Commit() error {
250245
return err
251246
}
252247

253-
if err := n.commitAddedDecisions(); err != nil {
254-
return err
255-
}
256-
257-
return nil
248+
return n.commitAddedDecisions()
258249
}
259250

260251
type tmpDecisions struct {
@@ -311,9 +302,5 @@ func (n *nft) ShutDown() error {
311302
return err
312303
}
313304

314-
if err := n.v6.shutDown(); err != nil {
315-
return err
316-
}
317-
318-
return nil
305+
return n.v6.shutDown()
319306
}

0 commit comments

Comments
 (0)