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).
Don't add fallbacks for values that are guaranteed present
Avoid `value ?? alternative` when the schema/migration guarantees the value exists; the fallback misrepresents the data contract.
Bad example
| 1 | // A migration backfilled priceInBase for every row, so it is never null. |
| 2 | // The fallback implies otherwise and may silently use the unconverted price. |
| 3 | const price = new Decimal(tx.priceInBase ?? tx.price); |
Explanation (EN)
The `?? tx.price` fallback suggests priceInBase can be missing, contradicting the migration that backfilled it, and risks using the wrong (unconverted) value.
Objašnjenje (HR)
Fallback `?? tx.price` sugerira da priceInBase moze nedostajati, sto je u suprotnosti s migracijom koja ga je popunila, i riskira koristenje pogresne (nekonvertirane) vrijednosti.
Good example
| 1 | // priceInBase is guaranteed by the migration; use it directly. |
| 2 | const price = new Decimal(tx.priceInBase); |
Explanation (EN)
Using the column directly reflects the real data contract and surfaces a genuine bug loudly if the value were ever unexpectedly null.
Objašnjenje (HR)
Izravno koristenje stupca odrazava stvarni ugovor podataka i glasno otkriva pravi bug ako bi vrijednost ikad neocekivano bila null.
Exceptions / Tradeoffs (EN)
Keep the fallback during a transition window if old rows genuinely lack the value and the backfill is not yet complete; remove it once the migration is verified. Balance against guard-array-before-iteration-methods: drop the [] fallback only when presence is guaranteed by your own validated boundary, not by an unverified external schema.
Iznimke / Tradeoffi (HR)
Zadrzi fallback tijekom prijelaznog razdoblja ako stari redovi stvarno nemaju vrijednost i backfill jos nije gotov; ukloni ga nakon sto je migracija potvrđena.