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).
Reject invalid scoped filters without broadening the query
If an absent or empty filter means all records downstream, never convert an invalid or oversized scoped selection into that representation. Reject it, return an explicit no-results state, or use a valid bounded subset only when partial results are part of the contract.
Bad example
| 1 | export function scopedParams(rawIds: readonly string[]): URLSearchParams { |
| 2 | const ids = rawIds.filter(id => /^\d+$/.test(id)).join(','); |
| 3 | return ids && ids.length <= 24 |
| 4 | ? new URLSearchParams({ ids }) |
| 5 | : new URLSearchParams(); |
| 6 | } |
Explanation (EN)
Invalid or oversized input silently drops the filter, allowing a consumer to request every record.
Objašnjenje (HR)
Nevaljan ili prevelik unos tiho uklanja filter pa potrošač može zatražiti sve zapise.
Good example
| 1 | export function scopedParams(rawIds: readonly string[]): URLSearchParams { |
| 2 | if (rawIds.length === 0 || rawIds.some(id => !/^\d+$/.test(id))) { |
| 3 | throw new Error('A scoped query requires valid identifiers'); |
| 4 | } |
| 5 | const ids = rawIds.join(','); |
| 6 | if (ids.length > 24) throw new Error('Selection exceeds the query limit'); |
| 7 | return new URLSearchParams({ ids }); |
| 8 | } |
Explanation (EN)
Invalid scoped input stops before the request. No error path produces an unfiltered query.
Objašnjenje (HR)
Neispravan odabir zaustavlja se prije zahtjeva. Nijedna grana pogreške ne stvara nefiltriran upit.
Notes (EN)
Check both the adapter and the downstream parser: retaining one oversized value is insufficient if the consumer rejects it as an empty filter. Cover all-invalid input, a single oversized identifier and an over-limit list. Callers must preserve the failure instead of catching it and retrying without the filter.
Bilješke (HR)
Provjeri i adapter i potrošačev parser: zadržavanje jedne preduge vrijednosti nije dovoljno ako je potrošač odbaci kao prazan filter. Pokrij potpuno nevaljan unos, jedan predug identifikator i prevelik popis. Pozivatelj ne smije nakon pogreške ponoviti zahtjev bez filtera.
Exceptions / Tradeoffs (EN)
An explicit user request for all records may legitimately omit the filter. Represent it separately from a failed scoped request. If truncation is acceptable, communicate the partial result and respect every downstream limit.
Iznimke / Tradeoffi (HR)
Izričit korisnikov zahtjev za svim zapisima smije izostaviti filter. Razlikuj ga od neuspjelog ograničenog zahtjeva. Ako je skraćivanje dopušteno, naznači djelomičan rezultat i poštuj sva ograničenja potrošača.