-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
golangci-lint: set go version to prevent fallback to go1.17, and fix copyloopvar linting issues #5594
Conversation
…opvar) go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; service/logs/parse_logs_test.go:50:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar) tc := tc ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
…opvar) go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; service/logs/parse_logs_test.go:50:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar) tc := tc ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
…pvar) go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; service/logs/parse_logs_test.go:50:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar) tc := tc ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; service/logs/parse_logs_test.go:50:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar) tc := tc ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
…oopvar) go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; service/logs/parse_logs_test.go:50:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar) tc := tc ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
…pvar) go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; service/logs/parse_logs_test.go:50:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar) tc := tc ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; service/logs/parse_logs_test.go:50:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar) tc := tc ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; service/logs/parse_logs_test.go:50:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar) tc := tc ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
…var) go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; service/logs/parse_logs_test.go:50:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar) tc := tc ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; cli/command/image/tree.go:59:4: The copy of the 'for' variable "im" can be deleted (Go 1.22+) (copyloopvar) im := im ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
…oopvar) go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; cli/command/container/opts.go:765:3: The copy of the 'for' variable "n" can be deleted (Go 1.22+) (copyloopvar) n := n ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
…var) go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; cli/compose/loader/merge.go:71:3: The copy of the 'for' variable "overrideService" can be deleted (Go 1.22+) (copyloopvar) overrideService := overrideService ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
…pvar) go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; cli/command/service/update.go:1061:3: The copy of the 'for' variable "entry" can be deleted (Go 1.22+) (copyloopvar) entry := entry ^ cli/command/service/update.go:1089:4: The copy of the 'for' variable "port" can be deleted (Go 1.22+) (copyloopvar) port := port ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
…pvar) go1.22 and up now produce a unique variable in loops, tehrefore no longer requiring to capture the variable manually; cli-plugins/manager/cobra.go:55:4: The copy of the 'for' variable "p" can be deleted (Go 1.22+) (copyloopvar) p := p ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
GolangCI-lint attempts to deduct the Go version to lint for through the go version specified in go.mod, which we don't have, and therefore it falls back to go1.17 semantics: level=warning msg="[linters_context] copyloopvar: this linter is disabled because the Go version (1.17) of your project is lower than Go 1.22 Signed-off-by: Sebastiaan van Stijn <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5594 +/- ##
==========================================
- Coverage 59.63% 59.63% -0.01%
==========================================
Files 346 346
Lines 29214 29208 -6
==========================================
- Hits 17421 17417 -4
+ Misses 10824 10822 -2
Partials 969 969 |
@@ -52,7 +52,6 @@ func AddPluginCommandStubs(dockerCli command.Cli, rootCmd *cobra.Command) (err e | |||
return | |||
} | |||
for _, p := range plugins { | |||
p := p |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just adding this here for future reference: https://go.dev/ref/spec#For_statements
Go 1.22 fixed iterations to use their own variables instead of sharing them. https://go.dev/ref/spec#Go_1.22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for linking that! Yes, indeed, they fixed that situation. I know they had some back-and-forth on fixing it, because it could be a breaking change, but ultimately they decided that fixing the "footgun" part outweighed the "breaking change" part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realised we were also setting go:
build-tags; not exactly sure if those would affect the behavior (i.e., if go would downgrade to go1.21 semantics, and thus disable the new behavior), but just in case it would, I opened a PR to update those;
GolangCI-lint attempts to deduct the Go version to lint for through the
go version specified in go.mod, which we don't have, and therefore it
falls back to go1.17 semantics:
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)