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).
Select only the columns your code actually uses
Project only the database columns the consuming code needs; don't add fields speculatively.
Bad example
| 1 | const rows = await db.select({ |
| 2 | id: quotes.id, |
| 3 | last: quotes.last, |
| 4 | bid: quotes.bid, |
| 5 | ask: quotes.ask, |
| 6 | vwap: quotes.vwap, // never read |
| 7 | dayHigh: quotes.dayHigh, // never read |
| 8 | dayLow: quotes.dayLow, // never read |
| 9 | }).from(quotes); |
| 10 |
|
| 11 | return rows.map((r) => ({ id: r.id, price: r.last })); |
Explanation (EN)
Three columns are fetched but never read. The query implies they matter, costs extra IO, and misleads the next reader about the data contract.
Objašnjenje (HR)
Tri stupca se dohvacaju, a nikad ne citaju. Upit sugerira da su vazni, trosi dodatni IO i zavarava sljedeceg citatelja o ugovoru podataka.
Good example
| 1 | const rows = await db.select({ |
| 2 | id: quotes.id, |
| 3 | last: quotes.last, |
| 4 | }).from(quotes); |
| 5 |
|
| 6 | return rows.map((r) => ({ id: r.id, price: r.last })); |
Explanation (EN)
Only the columns the mapping reads are selected. Add more fields when an actual consumer needs them.
Objašnjenje (HR)
Biraju se samo stupci koje mapiranje cita. Dodaj jos polja kada ih stvarni potrosac zatreba.
Notes (EN)
Same principle applies to over-broad DTOs and API responses: expose what is used, not what might be used someday.
Bilješke (HR)
Isto nacelo vrijedi za preopsezne DTO-ove i API odgovore: izlozi ono sto se koristi, a ne ono sto bi se mozda jednom koristilo.
Exceptions / Tradeoffs (EN)
A deliberately stable wire/contract shape that intentionally includes optional fields for forward compatibility.
Iznimke / Tradeoffi (HR)
Namjerno stabilan oblik ugovora koji namjerno ukljucuje opcionalna polja radi buduce kompatibilnosti.