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 port unused parameters and fields into a refactor
Before reimplementing a service or function, search for actual usages of each parameter/field and drop the ones nothing ever sets or reads instead of faithfully copying dead code forward.
Bad example
| 1 | // Old service exposed many filter fields. The route never set |
| 2 | // `excludeIds` or `paid`, but the rewrite copies them anyway. |
| 3 | export interface FeedQueryParams { |
| 4 | limit: number; |
| 5 | offset: number; |
| 6 | categoryIds?: string[]; |
| 7 | excludeIds?: string[]; // never set by any caller |
| 8 | paid?: boolean; // never read in old logic |
| 9 | } |
| 10 |
|
| 11 | export async function fetchFeed(params: FeedQueryParams) { |
| 12 | const repo = repository(); |
| 13 | if (params.categoryIds?.length) repo.byCategoryIds(params.categoryIds); |
| 14 | if (params.excludeIds?.length) repo.excludeIds(params.excludeIds); |
| 15 | // params.paid is threaded through but does nothing |
| 16 | return repo.asArray(); |
| 17 | } |
Explanation (EN)
The refactor preserves `excludeIds` and `paid` even though a usage search shows no caller ever set them and the old code never branched on `paid`. This drags dead surface area into the new abstraction, confuses future readers, and invites bugs from half-wired options.
Objašnjenje (HR)
Refaktoriranje zadržava `excludeIds` i `paid` iako pretraga upotrebe pokazuje da ih nijedan pozivatelj nikad nije postavljao, a stari kod nikad nije grananjem koristio `paid`. Time se mrtva povrsina prenosi u novu apstrakciju, zbunjuje buduce citatelje i otvara prostor za greske od poluspojenih opcija.
Good example
| 1 | // Keep only the parameters that callers actually provide and the |
| 2 | // implementation actually uses. |
| 3 | export interface FeedQueryParams { |
| 4 | limit: number; |
| 5 | offset: number; |
| 6 | categoryIds?: string[]; |
| 7 | } |
| 8 |
|
| 9 | export async function fetchFeed(params: FeedQueryParams) { |
| 10 | const repo = repository(); |
| 11 | if (params.categoryIds?.length) repo.byCategoryIds(params.categoryIds); |
| 12 | return repo.asArray(); |
| 13 | } |
Explanation (EN)
Each parameter that survives the refactor has a verified caller and a real effect. A quick grep for `excludeIds`/`paid` before reimplementing confirms they are dead and can be removed, keeping the new API minimal and honest.
Objašnjenje (HR)
Svaki parametar koji prezivi refaktoriranje ima provjerenog pozivatelja i stvarni ucinak. Brza pretraga za `excludeIds`/`paid` prije reimplementacije potvrdi da su mrtvi i da se mogu ukloniti, cime nova API ostaje minimalan i iskren.
Exceptions / Tradeoffs (EN)
Keep an unused parameter only when it is part of a stable public contract you cannot change yet, or a documented future extension point with a tracking reference.
Iznimke / Tradeoffi (HR)
Zadrzi neiskoristen parametar samo kad je dio stabilnog javnog ugovora koji jos ne smijes mijenjati ili dokumentirana buduca tocka prosirenja s referencom na zadatak.