-
Notifications
You must be signed in to change notification settings - Fork 38
feat: add generic ToPtr function with deprecation notice #244
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
feat: add generic ToPtr function with deprecation notice #244
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughAdds a generic ToPtr[T any](v T) *T helper and deprecates existing type-specific PtrX helpers by delegating them to ToPtr. Updates CHANGELOG with the addition and deprecations. Introduces unit tests validating ToPtr and ensuring backward compatibility of PtrX helpers across supported types. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (34.81%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #244 +/- ##
==========================================
+ Coverage 34.75% 34.81% +0.06%
==========================================
Files 111 111
Lines 12295 12296 +1
==========================================
+ Hits 4273 4281 +8
+ Misses 7670 7663 -7
Partials 352 352 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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: 0
🧹 Nitpick comments (1)
utils_test.go (1)
20-212: LGTM with optional refactor suggestion.The test coverage is comprehensive and correct:
TestToPtrvalidates pointer creation and value correctness for all supported typesTestPtrFunctionsBackwardCompatibilityensures deprecated functions still workTestToPtrVsPtrFunctionsverifies equivalence between the new and old implementationsConsider using
t.Run()to organize test cases for better readability and easier debugging:func TestToPtr(t *testing.T) { - // Test with bool - boolVal := true - boolPtr := ToPtr(boolVal) - if boolPtr == nil { - t.Errorf("ToPtr(bool) returned nil") - } - if *boolPtr != boolVal { - t.Errorf("ToPtr(bool) = %v, want %v", *boolPtr, boolVal) - } + t.Run("bool", func(t *testing.T) { + boolVal := true + boolPtr := ToPtr(boolVal) + if boolPtr == nil { + t.Errorf("ToPtr(bool) returned nil") + } + if *boolPtr != boolVal { + t.Errorf("ToPtr(bool) = %v, want %v", *boolPtr, boolVal) + } + }) - // Test with int - intVal := 42 - intPtr := ToPtr(intVal) - if intPtr == nil { - t.Errorf("ToPtr(int) returned nil") - } - if *intPtr != intVal { - t.Errorf("ToPtr(int) = %v, want %v", *intPtr, intVal) - } + t.Run("int", func(t *testing.T) { + intVal := 42 + intPtr := ToPtr(intVal) + if intPtr == nil { + t.Errorf("ToPtr(int) returned nil") + } + if *intPtr != intVal { + t.Errorf("ToPtr(int) = %v, want %v", *intPtr, intVal) + } + }) // Apply the same pattern to remaining test cases... }This pattern would make test output more granular and help identify specific failures quickly. The same refactor can be applied to the other test functions.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
CHANGELOG.md(1 hunks)utils.go(1 hunks)utils_test.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
utils_test.go (1)
utils.go (9)
ToPtr(22-22)PtrBool(26-26)PtrInt(30-30)PtrInt32(34-34)PtrInt64(38-38)PtrFloat32(42-42)PtrFloat64(46-46)PtrString(50-50)PtrTime(54-54)
🔇 Additional comments (3)
CHANGELOG.md (1)
5-6: LGTM!The CHANGELOG entries accurately document the new generic
ToPtrfunction and the deprecation of type-specific pointer helpers. The format is consistent with the existing changelog style.utils.go (2)
21-22: LGTM!The generic
ToPtrfunction is simple, idiomatic, and correctly implemented. It eliminates code duplication by providing a single implementation for all types.
24-54: LGTM!All deprecated pointer helper functions correctly delegate to
ToPtrand include proper deprecation notices. This maintains backward compatibility while encouraging users to migrate to the generic implementation.
a84ef79 to
9f109e6
Compare
|
Github automatically closed the previous stale PR because of my rebase I guess. |
|
@coderabbitai generate docstrings |
✅ Actions performedDocstrings generation started. |
Docstrings generation was requested by @SoulPancake. * #244 (comment) The following files were modified: * `utils.go`
|
Note Generated docstrings for this pull request at #245 |
|
I think there are no auxiliary doc changes required for this |
For #219
Replaced all the type wise ToPtr functions to internally call a common generic function for the same.
Along with deprecation notice of the current ones.
Description
What problem is being solved?
How is it being solved?
What changes are made to solve it?
References
Review Checklist
mainSummary by CodeRabbit