-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Add noniljson Linter to Enforce omitempty for Nullable Struct Fields
#4399
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
|
Hey, thank you for opening your first Pull Request ! |
|
In order for a pull request adding a linter to be reviewed, the linter and the PR must follow some requirements.
Pull Request Description
Linter
The Linter Tests Inside Golangci-lint
|
|
Hello, IMHO this will lead to many false positives. Also, Another problem is related to slices:
I tried the linter on a project, and it produced hundreds of false positives. I would recommend that you create a plugin. |
|
Thank you so much for the excellent review. I appreciate the time and effort you put into it. Your analysis has made it clear that although the |
|
Based on my previous comment, I'm not comfortable accepting this linter. I can see 3 possibilities:
|
|
Thank you for your feedback! I have considered incorporating this into |
checking presence implies reading tag content, so you do the same thing but you will also check the type of the field. I recommend opening an issue on the Based on my previous comments, I will refuse this linter. |
Add
noniljsonLinter to Enforceomitemptyfor Nullable Struct FieldsI propose the addition of the
noniljsonlinter to thegolangci-lintproject. Thenoniljsonlinter is a static analysis tool designed for Go, focusing on improving JSON serialization practices. It identifies nullable struct fields that, when marshaled into JSON, do not include theomitemptyoption, thus preventing these fields from being represented asnullin the output.Rationale
The inclusion of
nullvalues in JSON can introduce several challenges:nullValues: May lead to inconsistencies and errors in JSON consumers not designed to handlenull.nullincrease the JSON payload size, affecting transmission efficiency.Solution
noniljsonmitigates these issues by enforcing the addition of theomitemptytag in struct field definitions, ensuring a clean, efficient, and compliant JSON output. This linter thus serves as an invaluable tool for:nullvalues.Impact
Integrating
noniljsonintogolangci-lintprovides developers with an automated means to enforce best serialization practices, enhancing the quality, reliability, and interoperability of Go applications with external systems and services.Example
A common scenario identified by
noniljson: