From db2e6d75fad5dc7f3fea50413c72c64297a5fd32 Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Mon, 6 May 2024 11:13:18 +0300 Subject: [PATCH] Use go1.22, lint updates (#198) * Use go1.22, lint updates Signed-off-by: Kimmo Lehto * Go mod tidy Signed-off-by: Kimmo Lehto --------- Signed-off-by: Kimmo Lehto --- .golangci.yml | 36 +++++++++++++++++------------------- go.mod | 16 ++++++++-------- go.sum | 28 ++++++++++++++-------------- kv/decoder.go | 2 +- rigtest/assertions.go | 2 +- rigtest/mockrunner.go | 5 +++-- sh/shellescape/expand.go | 4 ++-- sh/shellescape/split.go | 2 +- sh/shellescape/unquote.go | 2 +- sshconfig/printer.go | 6 +++--- sshconfig/set.go | 12 ++++++------ 11 files changed, 57 insertions(+), 58 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 8a76431a..5c0f84a2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,47 +1,45 @@ run: timeout: 8m - skip-dirs-use-default: false - skip-files: - - ".*\\.gen\\.go" - - examples/* - - test/* tests: false allow-parallel-runners: true linters: enable-all: true disable: - - nonamedreturns + - deadcode + - depguard + - dogsled + - execinquery - exhaustivestruct - exhaustruct + - exhaustive - forbidigo - - gochecknoinits - gochecknoglobals + - gochecknoinits - gocognit # cyclop is used instead - gocyclo # cyclop is used instead - godox + - goheader - golint + - gomnd + - ifshort - interfacer - ireturn + - lll - maligned + - mnd - nlreturn + - nonamedreturns + - nosnakecase - paralleltest - scopelint - - tparallel - - wsl - - tagliatelle - structcheck - - nosnakecase - - deadcode - - varcheck - - ifshort - - goheader - - dogsled - - lll - - gomnd - - depguard - tagalign + - tagliatelle + - tparallel + - varcheck + - wsl linters-settings: funlen: diff --git a/go.mod b/go.mod index 3de208f5..02aa1d2c 100644 --- a/go.mod +++ b/go.mod @@ -1,24 +1,24 @@ module github.com/k0sproject/rig/v2 -go 1.21 +go 1.22.0 require ( github.com/Microsoft/go-winio v0.6.2 github.com/davidmz/go-pageant v1.0.2 - github.com/masterzen/winrm v0.0.0-20231128182143-52a9e15d5730 + github.com/masterzen/winrm v0.0.0-20231227165926-e811dad5ac77 github.com/stretchr/testify v1.9.0 golang.org/x/crypto v0.22.0 - golang.org/x/term v0.19.0 + golang.org/x/term v0.20.0 gopkg.in/yaml.v2 v2.4.0 ) require ( github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6 // indirect - github.com/bodgit/ntlmssp v0.0.0-20231128222409-0a45a2447e7c // indirect + github.com/bodgit/ntlmssp v0.0.0-20240405225621-bc7a66a52237 // indirect github.com/bodgit/windows v1.0.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/go-logr/logr v1.3.0 // indirect + github.com/go-logr/logr v1.4.1 // indirect github.com/gofrs/uuid v4.4.0+incompatible // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect @@ -31,8 +31,8 @@ require ( github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/tidwall/transform v0.0.0-20201103190739-32f242e2dbde // indirect - golang.org/x/net v0.23.0 // indirect - golang.org/x/sys v0.19.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/net v0.24.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 27ab66c4..28f7dd23 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6 h1:w0E0fgc1Y github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6/go.mod h1:nuWgzSkT5PnyOd+272uUmV0dnAnAn42Mk7PiQC5VzN4= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= -github.com/bodgit/ntlmssp v0.0.0-20231128222409-0a45a2447e7c h1:W7dgPjcG1Rx+wOtKeviTPYSrzf/Um/ew9wBXY0IjP2s= -github.com/bodgit/ntlmssp v0.0.0-20231128222409-0a45a2447e7c/go.mod h1:X0rVAs8xRc5mkV/xTR3yCWqCN64bVnLxjqI8DHAbN0k= +github.com/bodgit/ntlmssp v0.0.0-20240405225621-bc7a66a52237 h1:IRHxBGP4NtipmCHvxhEFpxuypBszYx+WRo6Wc6xxjXo= +github.com/bodgit/ntlmssp v0.0.0-20240405225621-bc7a66a52237/go.mod h1:ZcREh7an/iQI1JTsS+K9YAlig9Twd+OAGqB75LT+5+8= github.com/bodgit/windows v1.0.1 h1:tF7K6KOluPYygXa3Z2594zxlkbKPAOvqr97etrGNIz4= github.com/bodgit/windows v1.0.1/go.mod h1:a6JLwrB4KrTR5hBpp8FI9/9W9jJfeQ2h4XDXU74ZCdM= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -13,8 +13,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0= github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE= -github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= -github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= @@ -46,8 +46,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 h1:2ZKn+w/BJeL43sCxI2jhPLRv73oVVOjEKZjKkflyqxg= github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786/go.mod h1:kCEbxUJlNDEBNbdQMkPSp6yaKcRXVI6f4ddk8Riv4bc= -github.com/masterzen/winrm v0.0.0-20231128182143-52a9e15d5730 h1:zLVOWGRxX/IsRpqHjl0hjVq6BORcs7ubih+G2dGhTEs= -github.com/masterzen/winrm v0.0.0-20231128182143-52a9e15d5730/go.mod h1:qfAjztAGRm7J7Ci10OA9vrx8WRDM0mlhdsFu7gBtMK8= +github.com/masterzen/winrm v0.0.0-20231227165926-e811dad5ac77 h1:psY7rHKhnfqjTEgkleIYpF1vVxVfYsUYFTO/cL5Z6xM= +github.com/masterzen/winrm v0.0.0-20231227165926-e811dad5ac77/go.mod h1:otHfftEJdo9JWGoq9GcJRaeNLp/uhqNq8JOk5lL+8Ks= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -75,8 +75,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= +golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -85,19 +85,19 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= -golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= +golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/kv/decoder.go b/kv/decoder.go index f8666491..309654c0 100644 --- a/kv/decoder.go +++ b/kv/decoder.go @@ -139,7 +139,7 @@ func (ra *reflectAssigner) setup() error { } typ := elem.Type() - for i := 0; i < elem.NumField(); i++ { + for i := range elem.NumField() { field := elem.Field(i) structField := typ.Field(i) ra.fields = append(ra.fields, newFieldInfo(field, structField)) diff --git a/rigtest/assertions.go b/rigtest/assertions.go index 4ba5be8e..a6288420 100644 --- a/rigtest/assertions.go +++ b/rigtest/assertions.go @@ -17,7 +17,7 @@ type Receiver interface { NotReceived(matchFn CommandMatcher) error } -func logExtraMsg(t TestingT, msgAndArgs ...any) { +func logExtraMsg(t TestingT, msgAndArgs ...any) { //nolint:varnamelen if len(msgAndArgs) == 0 { return } diff --git a/rigtest/mockrunner.go b/rigtest/mockrunner.go index 728c7d79..e92b00a7 100644 --- a/rigtest/mockrunner.go +++ b/rigtest/mockrunner.go @@ -219,6 +219,7 @@ type MockWaiter struct { fn CommandHandler } +// Close the mock command. func (m *MockWaiter) Close() error { log.Trace(m.ctx, "closing waiter streams", log.KeyCommand, m.cmd) if in, ok := m.in.(io.Closer); ok { @@ -291,7 +292,7 @@ func (m *MockStarter) AddCommandOutput(matchFn CommandMatcher, output string) { }}) } -// AddCommandOutput adds a matcher and a function to the starter that writes the given output to the stdout of the process. +// AddCommandSuccess adds a command matcher that should always succeed. func (m *MockStarter) AddCommandSuccess(matchFn CommandMatcher) { m.matchers = append(m.matchers, matcher{fn: matchFn, waiterFn: func(a *A) error { log.Trace(a.Ctx, "returning nil from command", log.KeyCommand, a.Command) @@ -299,7 +300,7 @@ func (m *MockStarter) AddCommandSuccess(matchFn CommandMatcher) { }}) } -// AddCommandOutput adds a matcher and a function to the starter that writes the given output to the stdout of the process. +// AddCommandFailure adds a command matcher that should always fail with the given error. func (m *MockStarter) AddCommandFailure(matchFn CommandMatcher, err error) { m.matchers = append(m.matchers, matcher{fn: matchFn, waiterFn: func(a *A) error { log.Trace(a.Ctx, "returning error from command", log.KeyCommand, a.Command, log.KeyError, err) diff --git a/sh/shellescape/expand.go b/sh/shellescape/expand.go index 59bed050..17f069ee 100644 --- a/sh/shellescape/expand.go +++ b/sh/shellescape/expand.go @@ -152,7 +152,7 @@ func Expand(input string, opts ...ExpandOption) (string, error) { //nolint:cyclo stack := builderStack{} openParen := 0 - for i := 0; i < len(input); i++ { + for i := range len(input) { currCh := input[i] if inEscape { @@ -414,7 +414,7 @@ func expandCurly(input string) (string, error) { } idx := -1 - for i := 0; i < len(input); i++ { + for i := range len(input) { idx = i if !isValidVarNameChar(input[i], i == 0) { break diff --git a/sh/shellescape/split.go b/sh/shellescape/split.go index 7fa7356a..fa7ff903 100644 --- a/sh/shellescape/split.go +++ b/sh/shellescape/split.go @@ -18,7 +18,7 @@ func Split(input string) ([]string, error) { //nolint:cyclop var inDoubleQuotes, inSingleQuotes, isEscaped bool - for i := 0; i < len(input); i++ { + for i := range len(input) { currentChar := input[i] if isEscaped { diff --git a/sh/shellescape/unquote.go b/sh/shellescape/unquote.go index 20e701fc..594d66da 100644 --- a/sh/shellescape/unquote.go +++ b/sh/shellescape/unquote.go @@ -33,7 +33,7 @@ func Unquote(input string) (string, error) { //nolint:cyclop var inDoubleQuotes, inSingleQuotes, isEscaped bool - for i := 0; i < len(input); i++ { + for i := range len(input) { currentChar := input[i] if isEscaped { diff --git a/sshconfig/printer.go b/sshconfig/printer.go index 3beb1c22..7f6cfeae 100644 --- a/sshconfig/printer.go +++ b/sshconfig/printer.go @@ -99,7 +99,7 @@ func (p *printer) stringerslicejoin(key string, separator rune) (string, bool) { return "", false } sb := &strings.Builder{} - for i := 0; i < field.Len(); i++ { + for i := range field.Len() { if i > 0 { sb.WriteRune(separator) } @@ -187,7 +187,7 @@ func (p *printer) channeltimeout(key string) (string, bool) { } if field, err := p.get(key, reflect.Slice); err == nil { sb := &strings.Builder{} - for i := 0; i < field.Len(); i++ { + for i := range field.Len() { if s, ok := p.stringify(field.Index(i)); ok { if sb.Len() > 0 { sb.WriteRune(' ') @@ -223,7 +223,7 @@ func (p *printer) forward(key string) (string, bool) { } if field, err := p.get(key, reflect.Slice); err == nil { sb := &strings.Builder{} - for i := 0; i < field.Len(); i++ { + for i := range field.Len() { if s, ok := p.stringify(field.Index(i)); ok { if sb.Len() > 0 { sb.WriteRune(' ') diff --git a/sshconfig/set.go b/sshconfig/set.go index 0fcdbc52..9e77883d 100644 --- a/sshconfig/set.go +++ b/sshconfig/set.go @@ -173,7 +173,7 @@ func (s *Setter) discoverFields() { s.elemFields = make(map[string]reflect.Value) - for i := 0; i < s.elem.NumField(); i++ { + for i := range s.elem.NumField() { field := s.elem.Field(i) structField := s.elem.Type().Field(i) s.elemFields[structField.Name] = field @@ -1286,7 +1286,7 @@ func (s *Setter) ExpandSlice(key string) ([]string, error) { //nolint:cyclop return nil, nil } var values []string - for i := 0; i < field.Len(); i++ { + for i := range field.Len() { f := field.Index(i) switch { case f.Kind() == reflect.String: @@ -1318,7 +1318,7 @@ func (s *Setter) isInIgnoreUnknown(key string) bool { if err != nil { return false } - for i := 0; i < field.Len(); i++ { + for i := range field.Len() { match, err := patternMatch(key, field.Index(i).String()) if err != nil { return false @@ -1349,7 +1349,7 @@ func (s *Setter) matchesHost(conditions ...string) (bool, error) { // matchesMatch checks if the Match directive conditions are met. func (s *Setter) matchesMatch(conditions ...string) (bool, error) { //nolint:funlen,cyclop // TODO extract functions log.Trace(context.Background(), "matching Match directive", "conditions", conditions) - for i := 0; i < len(conditions); i++ { + for i := range len(conditions) { condition := conditions[i] log.Trace(context.Background(), "matching Match directive", "condition", condition) var negate bool @@ -1514,7 +1514,7 @@ func (s *Setter) hasProxyJump() bool { if proxyJump.Kind() == reflect.String { return proxyJump.String() != "" && proxyJump.String() != none } else if proxyJump.Kind() == reflect.Slice { - for i := 0; i < proxyJump.Len(); i++ { + for i := range proxyJump.Len() { if proxyJump.Index(i).String() != "" && proxyJump.Index(i).String() != none { return true } @@ -1637,7 +1637,7 @@ func (s *Setter) canonicalizePermittedCNAMEs() map[string]string { if permittedCnames.Len() == 0 || (permittedCnames.Len() == 1 && permittedCnames.Index(0).String() == none) { return res } - for i := 0; i < permittedCnames.Len(); i++ { + for i := range permittedCnames.Len() { parts := strings.Split(permittedCnames.Index(i).String(), ":") if len(parts) != 2 { continue