-
Couldn't load subscription status.
- Fork 239
Modernize go code using modernize tool #1819
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
Conversation
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.
Pull Request Overview
This PR modernizes the Go code by replacing the generic interface{} with the new any type and updating loop constructs using the range keyword and new helper functions (such as strings.SplitSeq). However, some of the automated for‑loop modifications now iterate over integers instead of iterables, which may introduce compilation errors.
- Updated method signatures by replacing interface{} with any.
- Replaced traditional for‑loop constructs with range expressions.
- Introduced new functions like strings.SplitSeq and slices package methods.
Reviewed Changes
Copilot reviewed 52 out of 52 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| component/azstorage/*.go | Updated getServiceClient return types to any. |
| common/version.go | Modified for‑loop iteration over a numeric literal. |
| common/util.go | Changed for‑loops for iterating over strings.Split and pids. |
| common/log/* | Updated logging function signatures to use any. |
| common/config/*.go | Updated merge and iteration loops to use any and range over int. |
| common/cache_policy/lru_policy.go | Modified for‑loop iteration over cache.List.Len() with range. |
| cmd/root.go | Updated for‑loops over string slices from strings.SplitSeq. |
| cmd/mount.go | Modified for‑loop iteration over a numeric literal using range. |
Comments suppressed due to low confidence (10)
cmd/root.go:81
- This change causes the loop to iterate over indices rather than string values from processes; restore the original 'for _, process := range processes' to correctly access the process strings.
for process := range processes {
cmd/mount.go:468
- Using 'for l := range 3' to iterate three times is invalid in Go since an integer is not an iterable; revert to a conventional loop to achieve the intended iteration.
for l := range 3 {
common/version.go:99
- Using 'for i := range 3' is not valid in Go, because 'range' requires an iterable (such as a slice, array, or map) rather than an integer literal.
for i := range 3 {
common/util.go:75
- Iterating with 'for line := range ...' over the result of strings.SplitSeq returns indices, not the actual string elements, which will break subsequent string processing.
for line := range strings.SplitSeq(string(mntList), "\n") {
common/util.go:110
- Using 'for pid := range pids' will iterate over the indices of the slice returned by strings.SplitSeq rather than the string values, likely causing logic errors.
for pid := range pids {
common/log/logger_test.go:51
- Attempting to iterate over an integer using range is not allowed in Go. A traditional loop (e.g. 'for i := 0; i < count; i++') should be used instead.
for i := range lts.log_rotate_test_count {
common/config/keys_tree.go:234
- Using 'range' on an integer (the result of elem.NumField()) is invalid; revert to the conventional for-loop format to iterate over struct fields.
for i := range elem.NumField() {
common/config/keys_tree.go:271
- Iterating over the number of fields with a range loop on an integer is incorrect. The classic for-loop (using an index variable starting from 0 up to elem.NumField()) is required here.
for i := range elem.NumField() {
common/cache_policy/lru_policy.go:171
- Using 'range' on the integer returned by cache.List.Len() is not valid; replace it with a traditional loop to iterate over the list length.
for range cache.List.Len() {
cmd/root.go:249
- Replacing the traditional iteration over opts with 'for o := range opts' will yield indices instead of the option values; use 'for _, o := range opts' to iterate over the actual elements.
for o := range opts {
611929c to
f7de06d
Compare
|
Thanks for your Contribution! |
Type of Change
Description
This PR improves some of the go code using more modern go code, such as using the slices package when working with slices and using the range keyword. These fixes were automatically applied using the go modernize tool provided by the go team. You can run this tool using
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix ./...How Has This Been Tested?
Ran unit tests locally.
Checklist
Related Links