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).
Prefer callback parameter destructuring for simple property reads
If a collection callback only reads one property from its item, destructure that property in the parameter list.
Bad example
| 1 | const timestamps = chartData.map(point => point.timestamp); |
| 2 | const selected = items.find(item => item.id === selectedId) ?? null; |
Explanation (EN)
The callback parameter name adds no value when the body only reads one field. It makes the callback slightly noisier than necessary.
Objašnjenje (HR)
Ime parametra ne donosi vrijednost kada tijelo callbacka cita samo jedno polje. Takav zapis je nepotrebno bucniji.
Good example
| 1 | const timestamps = chartData.map(({ timestamp }) => timestamp); |
| 2 | const selected = items.find(({ id }) => id === selectedId) ?? null; |
Explanation (EN)
Parameter destructuring keeps simple collection callbacks compact and makes the actual dependency obvious immediately.
Objašnjenje (HR)
Destrukturiranje parametra skracuje jednostavne callbacke nad kolekcijama i odmah pokazuje o kojem polju logika ovisi.
Exceptions / Tradeoffs (EN)
Keep the full parameter when the callback uses multiple fields, when the object itself is passed onward, or when destructuring hurts clarity.
Iznimke / Tradeoffi (HR)
Zadrzi cijeli parametar kada callback koristi vise polja, kada se cijeli objekt prosljeduje dalje ili kada destrukturiranje smanjuje jasnocu.