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).
backend ruleP0universalStack: typescript
null-safetycorrectnessdefensive-programming
Handle nullable return values before calling methods on them
When a helper can return null/undefined, guard the result before dereferencing it so you don't throw on the null case.
PR: hegnar-mws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | const decoded = decodeAuthHeader(header); // can return null |
| 2 | useToken(decoded.token); // throws when null |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const decoded = decodeAuthHeader(header); |
| 2 | if (!decoded) return false; |
| 3 | useToken(decoded.token); |
Explanation (EN)
Objašnjenje (HR)