-
Notifications
You must be signed in to change notification settings - Fork 4k
refactor(client): use map.Copy for cleaner map handling #24022
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
📝 WalkthroughWalkthroughThe changes involve modifications to the Changes
Suggested labels
Suggested reviewers
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
📜 Recent review detailsConfiguration used: .coderabbit.yml 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (2)`**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
`**/*_test.go`: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (5)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
client/v2/autocli/flag/maps/generic.go
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Golang code for conformity with the Ub...
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
client/v2/autocli/flag/maps/generic.go
🪛 GitHub Actions: Lint
client/v2/autocli/flag/maps/generic.go
[error] 5-5: File is not gci
-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order (gci)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Analyze
- GitHub Check: Summary
🔇 Additional comments (1)
client/v2/autocli/flag/maps/generic.go (1)
48-48
: Good use of maps.Copy for cleaner code.This change effectively uses the
maps.Copy
function introduced in Go 1.21 to replace what was likely a manual iteration loop. This results in cleaner, more maintainable code and leverages modern Go features as intended in the PR objectives.
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
client/v2/autocli/flag/maps/generic_test.go (1)
59-61
: Consider simplifying this lambda function too.For consistency, you could create a simple helper function for the keyParser too, especially since this same function is used in both test functions.
+// identityParser returns the input string unchanged with no error +func identityParser(s string) (string, error) { + return s, nil +} func TestGenericMapValue_Set(t *testing.T) { // ... gm.Options = genericMapValueOptions[string, int]{ - keyParser: func(s string) (string, error) { - return s, nil - }, + keyParser: identityParser,
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
client/v2/autocli/flag/maps/generic.go
(2 hunks)client/v2/autocli/flag/maps/generic_test.go
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- client/v2/autocli/flag/maps/generic.go
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.go`: Review the Golang code for conformity with the Ub...
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
client/v2/autocli/flag/maps/generic_test.go
`**/*_test.go`: "Assess the unit test code assessing suffici...
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"
client/v2/autocli/flag/maps/generic_test.go
🪛 GitHub Actions: Lint
client/v2/autocli/flag/maps/generic_test.go
[error] 62-62: unlambda: replace `func(s string) (int, error) {
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Summary
🔇 Additional comments (3)
client/v2/autocli/flag/maps/generic_test.go (3)
11-79
: LGTM! Well-structured table-driven test.The test covers a good range of scenarios including basic functionality, error handling, and edge cases for the map value's Set method. You've properly used maps.Copy to set up the test data, which aligns with the PR's objective.
🧰 Tools
🪛 GitHub Actions: Lint
[error] 62-62: unlambda: replace `func(s string) (int, error) {
81-106
: Good test for tracking map state changes.This test clearly demonstrates the expected behavior of the genericMapValue's change tracking - first replacing the map entirely, then merging with existing entries on subsequent calls. This validates the refactoring of the Set method using maps.Copy.
55-55
: Excellent use of maps.Copy.Using maps.Copy here is consistent with the PR's objective of leveraging this function for cleaner map handling. This is a good demonstration of the function that's being implemented in the actual code.
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.
great, thanks for the contribution
(cherry picked from commit ef81fc8) # Conflicts: # client/v2/autocli/flag/maps/generic.go
) (#24048) Co-authored-by: petersssong <[email protected]> Co-authored-by: aljo242 <[email protected]>
Description
since go.1.21 support
map.Copy
ref: https://pkg.go.dev/maps#Copy
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit
Refactor
Tests
Set
method and change tracking.