Skip to content

Commit 507d7ca

Browse files
committed
chore: updated linter settings and cleaning more things
1 parent 37eba54 commit 507d7ca

33 files changed

+220
-118
lines changed

.golangci.yaml

+49-59
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
linters-settings:
2-
depguard:
3-
list-type: blacklist
4-
dupl:
5-
threshold: 100
62
funlen:
7-
lines: 100
3+
lines: 150
84
statements: 50
9-
goconst:
10-
min-len: 2
11-
min-occurrences: 2
125
gocritic:
136
enabled-tags:
147
- diagnostic
@@ -17,95 +10,88 @@ linters-settings:
1710
- performance
1811
- style
1912
disabled-checks:
20-
- dupImport # https://github.com/go-critic/go-critic/issues/845
21-
- ifElseChain
22-
- octalLiteral
2313
- whyNoLint
24-
- wrapperFunc
2514
gocyclo:
2615
min-complexity: 15
27-
goimports:
28-
local-prefixes: github.com/golangci/golangci-lint
29-
gomnd:
30-
settings:
31-
mnd:
32-
# don't include the "operation" and "assign"
33-
checks: argument,case,condition,return
34-
govet:
35-
check-shadowing: true
36-
settings:
37-
printf:
38-
funcs:
39-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
40-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
41-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
42-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
4316
lll:
4417
line-length: 100
18+
tab-width: 4
4519
stylecheck:
4620
checks:
4721
- "-ST1000"
48-
misspell:
49-
locale: US
50-
nolintlint:
51-
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
52-
allow-unused: false # report any unused nolint directives
53-
require-explanation: false # don't require an explanation for nolint directives
54-
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
55-
revive:
56-
rules:
57-
- name: exported
22+
5823
linters:
5924
enable:
60-
- nlreturn
61-
- forbidigo
62-
- gofumpt
25+
- asciicheck
6326
- bodyclose
27+
- decorder
6428
- depguard
6529
- dogsled
6630
- dupl
31+
- dupword
32+
- durationcheck
6733
- errcheck
34+
- errchkjson
35+
- errname
36+
- errorlint
6837
- exhaustive
38+
- exportloopref
39+
- forbidigo
40+
- forcetypeassert
6941
- funlen
42+
- gocheckcompilerdirectives
43+
- gochecknoglobals
7044
- gochecknoinits
45+
- gocognit
7146
- goconst
7247
- gocritic
7348
- gocyclo
49+
- godot
50+
- godox
51+
- goerr113
7452
- gofmt
53+
- gofumpt
7554
- goimports
7655
- gomnd
7756
- goprintffuncname
7857
- gosec
7958
- gosimple
8059
- govet
60+
- grouper
61+
- importas
8162
- ineffassign
8263
- lll
64+
- maintidx
65+
- makezero
8366
- misspell
8467
- nakedret
68+
- nestif
69+
- nilerr
70+
- nlreturn
8571
- noctx
8672
- nolintlint
73+
- nolintlint
74+
- prealloc
75+
- predeclared
76+
- reassign
8777
- revive
88-
- rowserrcheck
89-
- exportloopref
9078
- staticcheck
9179
- stylecheck
80+
- tenv
81+
- testpackage
82+
- tparallel
9283
- typecheck
9384
- unconvert
9485
- unparam
9586
- unused
87+
- usestdlibvars
88+
- wastedassign
9689
- whitespace
97-
- asciicheck
98-
- gochecknoglobals
99-
- gocognit
100-
- godot
101-
- godox
102-
- goerr113
103-
- nestif
104-
- prealloc
105-
- testpackage
10690
- wsl
10791

10892
issues:
93+
max-issues-per-linter: 0
94+
max-same-issues: 0
10995
# https://github.com/golangci/golangci-lint/issues/2439#issuecomment-1002912465
11096
exclude-use-default: false
11197
exclude-rules:
@@ -116,20 +102,24 @@ issues:
116102
- structcheck
117103
- unused
118104
- unparam
105+
119106
# ignoring long lines due to json/yaml tags in platform
120107
- path: platform/definition.go
121108
linters:
122109
- lll
123110

111+
# ignore package comments complaints in revive
112+
- linters:
113+
- revive
114+
text: "package-comments"
115+
124116
run:
125-
# running w/ 1.17 because we dont actually need/use 1.18 things and 1.18 breaks some linters.
126-
go: '1.17'
117+
go: '1.19'
127118
skip-dirs:
128119
- private
129120

130-
# golangci.com configuration
131-
# https://github.com/golangci/golangci/wiki/Configuration
121+
output:
122+
uniq-by-line: false
123+
132124
service:
133-
golangci-lint-version: 1.49.x # use the fixed version to not introduce new linters unexpectedly
134-
prepare:
135-
- echo "here I can run custom commands, but no preparation needed for this repo"
125+
golangci-lint-version: 1.52.x

channel/auth.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func getAuthPatterns() *authPatterns {
3838
return authPatternsInstance
3939
}
4040

41-
func (c *Channel) authenticateSSH(p, pp []byte) *result { //nolint:dupl
41+
func (c *Channel) authenticateSSH(p, pp []byte) *result {
4242
pCount := 0
4343

4444
ppCount := 0
@@ -87,13 +87,15 @@ func (c *Channel) authenticateSSH(p, pp []byte) *result { //nolint:dupl
8787

8888
if ppCount > passphraseSeenMax {
8989
c.l.Critical(
90-
"private key passphrase prompt seen multiple times, assuming authentication failed",
90+
"private key passphrase prompt seen multiple times," +
91+
" assuming authentication failed",
9192
)
9293

9394
return &result{
9495
nil,
9596
fmt.Errorf(
96-
"%w: private key passphrase prompt seen multiple times, assuming authentication failed",
97+
"%w: private key passphrase prompt seen multiple times,"+
98+
" assuming authentication failed",
9799
util.ErrAuthError,
98100
),
99101
}
@@ -130,7 +132,7 @@ func (c *Channel) AuthenticateSSH(p, pp []byte) ([]byte, error) {
130132
}
131133
}
132134

133-
func (c *Channel) authenticateTelnet(u, p []byte) *result { //nolint:dupl
135+
func (c *Channel) authenticateTelnet(u, p []byte) *result {
134136
uCount := 0
135137

136138
pCount := 0

channel/channel.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
// bytes.
2727
DefaultPromptSearchDepth = 1_000
2828
redacted = "redacted"
29+
readDelayDivisor = 1_000
2930
)
3031

3132
var (
@@ -181,7 +182,7 @@ func (c *Channel) Close() error {
181182
c.l.Debug("closing underlying transport...")
182183

183184
return c.t.Close(false)
184-
case <-time.After(c.ReadDelay * (c.ReadDelay / 1000)):
185+
case <-time.After(c.ReadDelay * (c.ReadDelay / readDelayDivisor)): //nolint:durationcheck
185186
// channel is stuck in a blocking read (almost always the case for netconf!), force close
186187
// transport to finish closing connection, so give it c.ReadDelay*(c.ReadDelay/1000) to
187188
// "nicely" exit -- with defaults this ends up being 62.5ms.

channel/read.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package channel
22

33
import (
44
"bytes"
5+
"errors"
56
"io"
67
"regexp"
78
"time"
@@ -19,7 +20,7 @@ func (c *Channel) read() {
1920

2021
b, err := c.t.Read()
2122
if err != nil {
22-
if err == io.EOF {
23+
if errors.Is(err, io.EOF) {
2324
// the underlying transport was closed so just return
2425
return
2526
}

driver/generic/sendcommands.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ func (d *Driver) SendCommands(
3636

3737
if op.StopOnFailed && r.Failed != nil {
3838
d.Logger.Info(
39-
"encountered failed command, and stop on failed is true, discontinuing send commands operation",
39+
"encountered failed command, and stop on failed is true," +
40+
" discontinuing send commands operation",
4041
)
4142

4243
return m, err

driver/generic/sendwithcallbacks_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func testSendWithCallbacks(
3939

4040
if r.Failed != nil {
4141
t.Fatalf(
42-
"%s: response object indicates failure, this shouldn't happenf or send with callbacks",
42+
"%s: response object indicates failure,"+
43+
" this shouldn't happenf or send with callbacks",
4344
testName,
4445
)
4546
}

driver/netconf/capabilities.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (d *Driver) processServerCapabilities() error {
4343
}
4444

4545
func (d *Driver) determineVersion() error {
46-
if d.ServerHasCapability(v1Dot1Cap) {
46+
if d.ServerHasCapability(v1Dot1Cap) { //nolint: gocritic
4747
d.SelectedVersion = V1Dot1
4848
} else if d.ServerHasCapability(v1Dot0Cap) {
4949
d.SelectedVersion = V1Dot0
@@ -57,7 +57,8 @@ func (d *Driver) determineVersion() error {
5757
d.SelectedVersion = V1Dot0
5858
} else {
5959
return fmt.Errorf(
60-
"%w: user requested netconf version 1.0, but server does not support this capability",
60+
"%w: user requested netconf version 1.0,"+
61+
" but server does not support this capability",
6162
util.ErrNetconfError,
6263
)
6364
}
@@ -66,7 +67,8 @@ func (d *Driver) determineVersion() error {
6667
d.SelectedVersion = V1Dot1
6768
} else {
6869
return fmt.Errorf(
69-
"%w: user requested netconf version 1.1, but server does not support this capability",
70+
"%w: user requested netconf version 1.1,"+
71+
" but server does not support this capability",
7072
util.ErrNetconfError)
7173
}
7274
}

driver/netconf/deleteconfig.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package netconf //nolint: dupl
1+
package netconf
22

33
import (
44
"encoding/xml"

driver/netconf/driver.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ const (
5656
defaultNamespace = "urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults"
5757

5858
xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
59+
60+
initialMessageID = 101
5961
)
6062

6163
type netconfPatterns struct {
@@ -129,7 +131,7 @@ func NewDriver(
129131
Transport: gd.Transport,
130132
Channel: gd.Channel,
131133

132-
messageID: 101,
134+
messageID: initialMessageID,
133135

134136
messages: map[int][]byte{},
135137
messagesLock: &sync.Mutex{},

driver/netconf/lock_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func TestLockUnlock(t *testing.T) {
8989
}
9090
}
9191

92-
func testLockUnlockFunctional( //nolint: funlen
92+
func testLockUnlockFunctional(
9393
testName, platformName, transportName string,
9494
) func(t *testing.T) {
9595
return func(t *testing.T) {

driver/netconf/read.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ func (d *Driver) read() {
7070
}
7171

7272
if messageID != 0 {
73-
d.Logger.Debugf("Received message response for message ID '%d', storing", messageID)
73+
d.Logger.Debugf(
74+
"Received message response for message ID '%d', storing", messageID,
75+
)
7476

7577
d.storeMessage(messageID, b)
7678
}
7779

7880
if subID != 0 {
79-
d.Logger.Debugf("Received message response for subscription ID '%d', storing", subID)
81+
d.Logger.Debugf(
82+
"Received message response for subscription ID '%d', storing", subID,
83+
)
8084

8185
d.storeSubscriptionMessage(subID, b)
8286
}

driver/netconf/rpc_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestForceSelfClosingTags(t *testing.T) {
3131
},
3232
"empty_tag_with_attrs_and_spaces": {
3333
got: []byte(
34-
`<routing-policy xmlns="http://openconfig.net/yang/routing-policy"> </routing-policy>`,
34+
`<routing-policy xmlns="http://openconfig.net/yang/routing-policy"> </routing-policy>`, //nolint: lll
3535
),
3636
want: []byte(`<routing-policy xmlns="http://openconfig.net/yang/routing-policy"/>`),
3737
},

driver/netconf/validate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package netconf //nolint: dupl
1+
package netconf
22

33
import (
44
"encoding/xml"

driver/network/acquirepriv.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ func (d *Driver) escalate(target string) error {
110110
if !p.EscalateAuth || d.AuthSecondary == "" {
111111
if d.AuthSecondary == "" {
112112
d.Logger.Info(
113-
"no auth secondary set, but escalate target may require auth, trying with no password",
113+
"no auth secondary set, but escalate target may require auth," +
114+
" trying with no password",
114115
)
115116
}
116117

driver/network/sendcommand_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func getTestSendCommandFunctionalCommand(t *testing.T, testName, platformName st
121121

122122
func testSendCommandFunctional(
123123
testName, platformName, transportName string,
124-
testCase *sendCommandFunctionalTestcase,
124+
_ *sendCommandFunctionalTestcase,
125125
) func(t *testing.T) {
126126
return func(t *testing.T) {
127127
t.Logf("%s: starting", testName)

driver/network/sendcommands_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func getTestSendCommandsFunctionalCommand(t *testing.T, testName, platformName s
194194

195195
func testSendCommandsFunctional(
196196
testName, platformName, transportName string,
197-
testCase *sendCommandsFunctionalTestcase,
197+
_ *sendCommandsFunctionalTestcase,
198198
) func(t *testing.T) {
199199
return func(t *testing.T) {
200200
t.Logf("%s: starting", testName)

0 commit comments

Comments
 (0)