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).
Prefer a positive filter predicate over a negated exclusion predicate
Filter on the condition for what you want to keep rather than negating a predicate for what you want to drop.
Bad example
| 1 | // Double-negative: keep everything that is NOT inactive. |
| 2 | const visible = users |
| 3 | .filter((u): u is ActiveUser => !isInactiveUser(u)) |
| 4 | .map(render); |
Explanation (EN)
Filtering by negating an 'unwanted' predicate forces the reader to mentally invert the condition to understand which items survive, which is slower to parse and easy to get backwards.
Objašnjenje (HR)
Filtriranje negiranjem predikata za 'nezeljeno' tjera citatelja da mentalno obrne uvjet kako bi shvatio koji elementi prezive, sto je sporije za citanje i lako se zamijeni smjer.
Good example
| 1 | // Keep exactly what we render. |
| 2 | const visible = users |
| 3 | .filter(isActiveUser) |
| 4 | .map(render); |
Explanation (EN)
When you care about the set you keep, a positive predicate states the intent directly so the filter reads as 'keep the active users' with no mental inversion.
Objašnjenje (HR)
Kad ti je bitan skup koji zadrzavas, pozitivan predikat izravno iskazuje namjeru pa se filter cita kao 'zadrzi aktivne korisnike' bez mentalnog obrtanja.
Exceptions / Tradeoffs (EN)
If the natural domain concept is the exclusion (e.g. 'remove blocked users') and that reads more clearly than its inverse, the negated form can be the better choice.
Iznimke / Tradeoffi (HR)
Ako je prirodni domenski koncept iskljucivanje (npr. 'ukloni blokirane korisnike') i to se cita jasnije od inverza, negirani oblik moze biti bolji izbor.