Skip to content

Conversation

@Not-Dhananjay-Mishra
Copy link
Contributor

Added handling for the ,omitzero tag option in processTag (structfield.go) by stripping it from the tag value before further validation, consistent with existing ,omitempty behavior.

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Dec 15, 2025
@gmlewis gmlewis changed the title Handle omitzero in structfield linter feat: Handle omitzero in structfield linter Dec 15, 2025
@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.48%. Comparing base (8ca48dd) to head (e6ec5c6).
⚠️ Report is 4 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@gmlewis gmlewis left a 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)

@Not-Dhananjay-Mishra
Copy link
Contributor Author

@gmlewis I added some test cases

No warning -

  • SliceOfZerosStructs []*Struct json:"slice_of_zeros_structs,omitzero"
  • SliceOfBothOmitTags []*Struct json:"slice_of_both_omit_tags,omitempty,omitzero"

Has warning -

  • SliceOfZeroInts []*int json:"slice_of_zero_ints,omitzero"
  • SliceOfBothOmitTags []*int json:"slice_of_both_omit_tags,omitempty,omitzero"
  • PerPageZeros int url:"per_page_zeros,omitzero"
  • PerPageBoth int url:"per_page_both,omitempty,omitzero"

@Not-Dhananjay-Mishra
Copy link
Contributor Author

Just to confirm, are we going to use omitzero with the following conditions?

  • Slice of pointer structs
  • Slice of non-pointer data types (int, string)
  • Pointer data types

Comment on lines 39 to 40
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"`
Copy link
Collaborator

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

Copy link
Contributor

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.

Copy link
Contributor Author

@Not-Dhananjay-Mishra Not-Dhananjay-Mishra Dec 16, 2025

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.

For these type of data? am i correct?

  • []*Struct
  • []string/int/...
  • Struct (or *Struct)
  • map

@gmlewis
Copy link
Collaborator

gmlewis commented Dec 16, 2025

Just to confirm, are we going to use omitzero with the following conditions?

  • Slice of pointer structs
  • Slice of non-pointer data types (int, string)
  • Pointer data types

HAH! We were typing at the same time!

Excellent questions!!! I don't know the answers. I'd like to hear some more opinions.

@Not-Dhananjay-Mishra
Copy link
Contributor Author

Not-Dhananjay-Mishra commented Dec 16, 2025

Now omitzero is :

Allowed with -

  • []builtin & []*builtin
  • map & *map
  • Struct & *Struct
  • []Struct & []*Struct

Not Allowed with -

  • with URL Tag
  • builtin & *builtin
  • *[]builtin/Struct & *[]*builtin/Struct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NeedsReview PR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants