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).
Name methods to match their return cardinality
Use plural names for methods returning collections and singular names for single values, so the signature reads honestly.
Bad example
| 1 | async getInstrument(insrefs: number[]): Promise<Instrument[]> { |
| 2 | return this.search.byInsrefs(insrefs); |
| 3 | } |
Explanation (EN)
The singular `getInstrument` returns an array, so callers expect one value and must re-read the body to learn the truth.
Objašnjenje (HR)
Jednina `getInstrument` vraća niz, pa pozivatelji očekuju jednu vrijednost i moraju iznova čitati tijelo da otkriju istinu.
Good example
| 1 | async getInstruments(insrefs: number[]): Promise<Instrument[]> { |
| 2 | return this.search.byInsrefs(insrefs); |
| 3 | } |
Explanation (EN)
The plural name matches the array return type, so the call site reads correctly at a glance.
Objašnjenje (HR)
Ime u množini odgovara povratnom tipu niza, pa se mjesto poziva ispravno čita na prvi pogled.