Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Don't send undefined values in request bodies; omit the key
When a request contract requires an absent key, omit only its defined missing-value cases and preserve valid falsy values.
Bad example
| 1 | const body = { name, parentId: selectedLocation.id ?? undefined }; |
Explanation (EN)
A truthiness spread can accidentally omit a valid zero identifier; omission must follow the request schema.
Objašnjenje (HR)
Good example
| 1 | const parentId = selectedLocation.id; |
| 2 | const body = { name, ...(parentId == null ? {} : { parentId }) }; |
Explanation (EN)
Only null and undefined are omitted; zero remains a valid supplied identifier.
Objašnjenje (HR)
Notes (EN)
At a request boundary, determine whether the consumer distinguishes an absent property, undefined and null. Preserve valid zero and false values when omitting only missing inputs.
Exceptions / Tradeoffs (EN)
JSON.stringify already omits undefined object properties, but in-memory validators, own-key checks and non-JSON serializers may distinguish them.