-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: Handle omitzero in structfield linter
#3881
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
base: master
Are you sure you want to change the base?
feat: Handle omitzero in structfield linter
#3881
Conversation
omitzero in structfield linteromitzero in structfield linter
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3881 +/- ##
=======================================
Coverage 92.48% 92.48%
=======================================
Files 200 200
Lines 14564 14564
=======================================
Hits 13469 13469
Misses 895 895
Partials 200 200 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
gmlewis
left a comment
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.
Thank you, @Not-Dhananjay-Mishra!
Please add test cases in all the test data that includes new ",omitzero" and ",omitempty,omitzero". I see you added one, but we need examples for all 4 possibilities. (warning, non-warning, single flag, double flags)
|
@gmlewis I added some test cases No warning -
Has warning -
|
|
Just to confirm, are we going to use
|
| PerPageZeros int `url:"per_page_zeros,omitzero"` // want `change the "PerPageZeros" field type to "\*int" in the struct "URLFieldType" because its tag uses "omitzero"` | ||
| PerPageBoth int `url:"per_page_both,omitempty,omitzero"` // want `change the "PerPageBoth" field type to "\*int" in the struct "URLFieldType" because its tag uses "omitempty and omitzero"` |
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.
OK, now here is where I'm a bit fuzzy - do we want to require using pointers for primitives when using omitzero? Do we want to allow omitzero at all for primitives?
I'm guessing the answer is "it depends on the particular field and its usage", but honestly I don't have experience with omitzero.
Thoughts?
cc: @stevehipwell - @alexandear - @zyfy29
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 propose narrowing the scope and allowing omitzero only for slices, maps, and structs. These are the cases where omitzero reduces a bit of boilerplate.
Maybe in the future we can use omitzero for primitives, but I'm not sure.
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 propose narrowing the scope and allowing
omitzeroonly for slices, maps, and structs. These are the cases whereomitzeroreduces a bit of boilerplate.
For these type of data? am i correct?
- []*Struct
- []string/int/...
- Struct (or *Struct)
- map
HAH! We were typing at the same time! Excellent questions!!! I don't know the answers. I'd like to hear some more opinions. |
|
Now Allowed with -
Not Allowed with -
|
Added handling for the
,omitzerotag option in processTag (structfield.go) by stripping it from the tag value before further validation, consistent with existing,omitemptybehavior.