Skip to content

feat(fields): read/set all the fields from the given struct#8

Closed
bkrukowski wants to merge 39 commits intomainfrom
feat/callbacks
Closed

feat(fields): read/set all the fields from the given struct#8
bkrukowski wants to merge 39 commits intomainfrom
feat/callbacks

Conversation

@bkrukowski
Copy link
Member

No description provided.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @bkrukowski - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 5 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 3 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Docstrings: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

setter/setter.go Outdated
func Set(strct any, field string, val any, convert bool) error {
return reflect.Set(strct, field, val, convert)
return intReflect.Set(strct, field, val, convert)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_clarification): Consider documenting the CallbackOption type and its intended use.

Public types and functions should have comments explaining their purpose, especially in a library setting. This helps users understand how to use them effectively.

setter/setter.go Outdated
func Set(strct any, field string, val any, convert bool) error {
return reflect.Set(strct, field, val, convert)
return intReflect.Set(strct, field, val, convert)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_clarification): Missing documentation for ConvertType function.

As a public function, ConvertType should have a comment explaining its purpose, parameters, and effects.

setter/setter.go Outdated
func Set(strct any, field string, val any, convert bool) error {
return reflect.Set(strct, field, val, convert)
return intReflect.Set(strct, field, val, convert)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_clarification): Missing documentation for ConvertToPointer function.

It's important to document public functions to guide users on their usage. ConvertToPointer should have a clear description.

setter/setter.go Outdated
func Set(strct any, field string, val any, convert bool) error {
return reflect.Set(strct, field, val, convert)
return intReflect.Set(strct, field, val, convert)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (code_clarification): Clarify behavior when ok == false in SetByCallback documentation.

The documentation should explicitly state what happens when the callback returns ok == false. Does it skip the field, or is there a default behavior?

setter/setter.go Outdated
func Set(strct any, field string, val any, convert bool) error {
return reflect.Set(strct, field, val, convert)
return intReflect.Set(strct, field, val, convert)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Consider making callbackConfig public or providing a public constructor.

Since callbackConfig is used in public API functions, users might need to construct it directly or access its fields.


func ExampleSetByCallback() {
var person struct {
Name string `custom:"name"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Consider adding a test case for SetByCallback with conversion options.

The current test case for SetByCallback does not cover scenarios where conversion options (ConvertType and ConvertToPointer) are used. It would be beneficial to add test cases that utilize these options to ensure they work as expected.


func ExampleSetByCallback() {
var person struct {
Name string `custom:"name"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Add negative test cases for SetByCallback.

It's important to also test how SetByCallback behaves under error conditions or when the callback returns false. Consider adding tests where the callback intentionally fails to find a matching tag or value in the config map.


func ExampleSetByCallback() {
var person struct {
Name string `custom:"name"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Verify the final state of person struct in ExampleSetByCallback.

The test case ExampleSetByCallback sets values on a person struct but does not assert or verify the final state of the struct. It would be useful to add an output comment at the end of the function to verify that the person struct was correctly modified.

@coveralls
Copy link

coveralls commented Sep 23, 2024

Pull Request Test Coverage Report for Build 11133530666

Details

  • 176 of 222 (79.28%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-5.0%) to 92.279%

Changes Missing Coverage Covered Lines Changed/Added Lines %
fields/iterate.go 99 101 98.02%
fields/path.go 9 27 33.33%
internal/reflect/iterate.go 46 72 63.89%
Totals Coverage Status
Change from base Build 11133485394: -5.0%
Covered Lines: 741
Relevant Lines: 803

💛 - Coveralls

@bkrukowski bkrukowski changed the title feat(callbacks): draft of the setter.SetByCallback feat(fields): read/set all the fields from the given struct Sep 23, 2024
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 1, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
4.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@bkrukowski
Copy link
Member Author

Moved to #10

@bkrukowski bkrukowski closed this Oct 1, 2024
@bkrukowski bkrukowski deleted the feat/callbacks branch October 1, 2024 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments