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).
Document historical data assumptions in enrichment fallbacks
When adding enrichment logic for missing names or metadata, encode and document the data assumption it protects against.
Bad example
| 1 | const getMissingInstrumentIds = (rows, instruments) => { |
| 2 | const currentIds = new Set(instruments.map(instrument => instrument.instrumentId)); |
| 3 | return rows.filter(row => !currentIds.has(row.instrumentId)).map(row => row.instrumentId); |
| 4 | }; |
Explanation (EN)
The code may be correct, but the intent is hidden. Reviewers cannot tell whether this handles stale data, deleted holdings, pagination gaps, or something else.
Objašnjenje (HR)
Kod mozda jest tocan, ali je namjera skrivena. Revieweri ne mogu znati pokriva li ovo stale data, obrisane holdinge, pagination gapove ili nesto drugo.
Good example
| 1 | // Transactions can reference historical instruments that are no longer present in current holdings. |
| 2 | const getHistoricalInstrumentIdsMissingFromHoldings = (rows, holdings) => { |
| 3 | const holdingIds = new Set(holdings.map(holding => holding.instrumentId)); |
| 4 | return rows |
| 5 | .filter(row => !holdingIds.has(row.instrumentId)) |
| 6 | .map(row => row.instrumentId); |
| 7 | }; |
Explanation (EN)
The fallback remains, but its purpose is explicit. Readers understand why the extra lookup exists and under which data model it is necessary.
Objašnjenje (HR)
Fallback ostaje, ali je njegova svrha eksplicitna. Citac razumije zasto dodatni lookup postoji i pod kojim data modelom je potreban.
Notes (EN)
Prefer intent-revealing names and one short comment when the fallback exists because current-state data differs from historical-state data.
Bilješke (HR)
Preferiraj imena koja otkrivaju namjeru i jedan kratak komentar kada fallback postoji zato sto se current-state data razlikuje od historical-state data.
Exceptions / Tradeoffs (EN)
Do not add comments for obvious transformations; use this only when the data assumption would otherwise be unclear in review.
Iznimke / Tradeoffi (HR)
Nemoj dodavati komentare za ocite transformacije; koristi ovo samo kada bi data pretpostavka inace bila nejasna u reviewu.