Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Filter out undefined items before mapping to UI, or make data mandatory
Rather than each render function returning null for missing data, filter undefined entries out of the array up front (or require the data), so the rendering code can assume valid items.
Bad example
| 1 | const renderChannel = (ch?: Channel) => { if (!ch) return null; /* ... */ }; |
Explanation (EN)
Repeated nullable checks can obscure rendering when normalization already owns absence handling.
Objašnjenje (HR)
Good example
| 1 | const channels = raw.filter((c): c is Channel => !!c); |
| 2 | const renderChannel = (ch: Channel) => { /* ... */ }; |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Normalize an optional collection once when every downstream renderer should receive a present item and missing entries have no layout meaning.
Exceptions / Tradeoffs (EN)
Filtering changes indices and may remove intentional placeholder slots. Use a truthful type predicate based on the known input union, not a cast-like predicate over unknown data.