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).
Comment the origin of ambient global declarations
When augmenting global types (e.g. Window) for third-party scripts, add a short comment naming what injects each global.
Bad example
| 1 | interface Window { |
| 2 | Header?: { user?: { accessLevel?: string } }; |
| 3 | adSdk?: { loadAd: (id: string) => void }; |
| 4 | _consent?: unknown[]; |
| 5 | } |
Explanation (EN)
Nothing tells a reader which external script provides each global or why it's declared, making the augmentation hard to maintain.
Objašnjenje (HR)
Nista ne govori citatelju koja vanjska skripta pruza svaki global ili zasto je deklariran, pa je augmentacija tesko odrziva.
Good example
| 1 | interface Window { |
| 2 | // injected by the auth header bundle |
| 3 | Header?: { user?: { accessLevel?: string } }; |
| 4 | // injected by the ad SDK loader script |
| 5 | adSdk?: { loadAd: (id: string) => void }; |
| 6 | // queue populated by the consent management script |
| 7 | _consent?: unknown[]; |
| 8 | } |
Explanation (EN)
Each comment names the script that provides the global, so the next maintainer understands its origin and lifecycle.
Objašnjenje (HR)
Svaki komentar imenuje skriptu koja pruza global, pa sljedeci odrzavatelj razumije njegovo porijeklo i zivotni ciklus.