Skip to content

Commit 6200445

Browse files
Merge pull request scrapli#125 from scrapli/chore/linterupdates
Chore/linterupdates
2 parents 60d1837 + 9638a65 commit 6200445

File tree

84 files changed

+280
-254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+280
-254
lines changed

.github/workflows/commit.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: lint
3232
uses: golangci/golangci-lint-action@v3
3333
with:
34-
version: v1.50
34+
version: v1.52
3535
args: --timeout 5m
3636
- name: install gotestsum
3737
run: go install gotest.tools/gotestsum@latest

.golangci.yaml

+48-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,87 @@ 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
6836
- exhaustive
37+
- exportloopref
38+
- forbidigo
39+
- forcetypeassert
6940
- funlen
41+
- gocheckcompilerdirectives
42+
- gochecknoglobals
7043
- gochecknoinits
44+
- gocognit
7145
- goconst
7246
- gocritic
7347
- gocyclo
48+
- godot
49+
- godox
50+
- goerr113
7451
- gofmt
52+
- gofumpt
7553
- goimports
7654
- gomnd
7755
- goprintffuncname
7856
- gosec
7957
- gosimple
8058
- govet
59+
- grouper
60+
- importas
8161
- ineffassign
8262
- lll
63+
- maintidx
64+
- makezero
8365
- misspell
8466
- nakedret
67+
- nestif
68+
- nilerr
69+
- nlreturn
8570
- noctx
8671
- nolintlint
72+
- nolintlint
73+
- prealloc
74+
- predeclared
75+
- reassign
8776
- revive
88-
- rowserrcheck
89-
- exportloopref
9077
- staticcheck
9178
- stylecheck
79+
- tenv
80+
- testpackage
81+
- tparallel
9282
- typecheck
9383
- unconvert
9484
- unparam
9585
- unused
86+
- usestdlibvars
87+
- wastedassign
9688
- whitespace
97-
- asciicheck
98-
- gochecknoglobals
99-
- gocognit
100-
- godot
101-
- godox
102-
- goerr113
103-
- nestif
104-
- prealloc
105-
- testpackage
10689
- wsl
10790

10891
issues:
92+
max-issues-per-linter: 0
93+
max-same-issues: 0
10994
# https://github.com/golangci/golangci-lint/issues/2439#issuecomment-1002912465
11095
exclude-use-default: false
11196
exclude-rules:
@@ -116,20 +101,24 @@ issues:
116101
- structcheck
117102
- unused
118103
- unparam
104+
119105
# ignoring long lines due to json/yaml tags in platform
120106
- path: platform/definition.go
121107
linters:
122108
- lll
123109

110+
# ignore package comments complaints in revive
111+
- linters:
112+
- revive
113+
text: "package-comments"
114+
124115
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'
116+
go: '1.19'
127117
skip-dirs:
128118
- private
129119

130-
# golangci.com configuration
131-
# https://github.com/golangci/golangci/wiki/Configuration
120+
output:
121+
uniq-by-line: false
122+
132123
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"
124+
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/generic/test-fixtures/golden/send-commands-from-file-simple-out.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
Building configuration...
42

53
Current configuration : 38 bytes

driver/generic/test-fixtures/golden/send-commands-simple-out.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
Building configuration...
42

53
Current configuration : 38 bytes

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/test-fixtures/golden/functional-getconfig-simple-arista_eos-standard-out.txt

+1-1
Large diffs are not rendered by default.

driver/netconf/test-fixtures/golden/functional-getconfig-simple-arista_eos-system-out.txt

+1-1
Large diffs are not rendered by default.

driver/netconf/test-fixtures/golden/functional-getconfig-simple-cisco_iosxe-standard-out.txt

+1-1
Large diffs are not rendered by default.

driver/netconf/test-fixtures/golden/functional-getconfig-simple-cisco_iosxe-system-out.txt

+1-1
Large diffs are not rendered by default.

driver/netconf/test-fixtures/golden/functional-getconfig-simple-cisco_nxos-standard-out.txt

-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
</If-list>
3333
</if-items>
3434
</Dom-list>
35-
<Dom-list>
36-
<name>default</name>
37-
</Dom-list>
3835
</dom-items>
3936
<evpn_timeout>600</evpn_timeout>
4037
<ipAdjRouteDistance>250</ipAdjRouteDistance>

0 commit comments

Comments
 (0)