Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Validate code under strict null checks
Enable strict null checking so possibly-undefined access is caught at compile time, not in production.
Bad example
| 1 | // tsconfig with strictNullChecks: false |
| 2 | function getCity(user: User) { |
| 3 | // user.address is possibly undefined, but the compiler stays silent |
| 4 | return user.address.city; // crashes at runtime when address is undefined |
| 5 | } |
Explanation (EN)
With strict null checks off, the compiler does not flag access on a possibly-undefined property. The code compiles cleanly and then throws a TypeError in production.
Objašnjenje (HR)
Kad su strict null provjere isključene, kompajler ne označava pristup potencijalno nedefiniranom svojstvu. Kod se uredno kompajlira, a zatim baca TypeError u produkciji.
Good example
| 1 | // tsconfig with strictNullChecks: true |
| 2 | function getCity(user: User) { |
| 3 | // compiler forces you to handle the undefined case |
| 4 | return user.address?.city ?? 'Unknown'; |
| 5 | } |
Explanation (EN)
With strict null checks on, the compiler requires the undefined case to be handled, forcing safe access patterns and eliminating the crash before the code ships.
Objašnjenje (HR)
Kad su strict null provjere uključene, kompajler zahtijeva da se obradi slučaj 'undefined', čime se nameću sigurni obrasci pristupa i uklanja se rušenje prije nego što kod ode u produkciju.
Notes (EN)
If a project cannot flip the global flag yet, at least type-check changed code under strict null checks before merging to catch new null-safety issues.
Bilješke (HR)
Ako projekt još ne može uključiti globalnu zastavicu, barem provjeri promijenjeni kod pod strict null provjerama prije spajanja kako bi uhvatio nove probleme sigurnosti od null vrijednosti.