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).
Explain edge-case handling with a why comment
When code exists only to cover a non-obvious edge case, add a brief comment describing the concrete scenario so it isn't mistaken for dead code.
Bad example
| 1 | window.addEventListener('resize', scheduleCheck, { signal }); |
Explanation (EN)
It's unclear why resize matters here; a future reader may delete it as redundant with scroll, breaking the edge case it silently guards.
Objašnjenje (HR)
Nije jasno zasto je resize ovdje bitan; buduci citatelj ga moze izbrisati kao suvisan uz scroll, cime se rusi rubni slucaj koji on tiho stiti.
Good example
| 1 | // On a large viewport the whole page can fit, so a resize can flip |
| 2 | // the header from sticky (mobile) to non-sticky (desktop). |
| 3 | window.addEventListener('resize', scheduleCheck, { signal }); |
Explanation (EN)
The comment names the concrete scenario, so the line reads as deliberate edge-case handling and survives future cleanups.
Objašnjenje (HR)
Komentar imenuje konkretan scenarij, pa se linija cita kao namjerno rjesavanje rubnog slucaja i prezivljava buduca ciscenja.
Exceptions / Tradeoffs (EN)
Balance against no-comments-restating-self-documenting-code: add a comment when the reason for an edge-case branch is non-obvious from the code alone.