Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
fullstack ruleP2universalStack: typescript
functionalreadabilitydata-transformationmaintainability
Build conditional payloads declaratively, not with stacked ifs
Assemble an object of all candidate fields, then filter by a whitelist and non-null check in one pass, instead of mutating the payload through a chain of if statements.
PR: hegnar-journalist-boost · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | const p = { title, content }; |
| 2 | if (push.seoTitle && seo?.seoTitle) p.seoTitle = seo.seoTitle; |
| 3 | if (push.authorId && authorId) p.authorId = authorId; |
| 4 | // ...repeated per field |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const optional = { seoTitle: seo?.seoTitle, authorId, categoryId }; |
| 2 | const filtered = Object.fromEntries( |
| 3 | Object.entries(optional).filter(([k, v]) => fieldsToPush[k] && v != null), |
| 4 | ); |
| 5 | await push({ title, content, ...filtered }); |
Explanation (EN)
Objašnjenje (HR)