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).
Destructure repeatedly used fields from the same object
When several fields from one object are used together, destructure them once instead of repeating property access.
Bad example
| 1 | const summary = { |
| 2 | id: response.id, |
| 3 | name: response.name, |
| 4 | order: response.order, |
| 5 | showBenchmark: response.showBenchmark, |
| 6 | includeDividends: response.includeDividends, |
| 7 | }; |
Explanation (EN)
Repeated property access creates noise and makes related fields harder to scan as one group. It also makes follow-up edits easier to miss.
Objašnjenje (HR)
Ponavljanje pristupa svojstvima stvara sum i oteza citanje povezanih polja kao cjeline. Takoder povecava sansu da se neki kasniji edit propusti.
Good example
| 1 | const { id, name, order, showBenchmark, includeDividends } = response; |
| 2 |
|
| 3 | const summary = { |
| 4 | id, |
| 5 | name, |
| 6 | order, |
| 7 | showBenchmark, |
| 8 | includeDividends, |
| 9 | }; |
Explanation (EN)
Destructuring makes the used contract explicit once and keeps the rest of the code smaller and easier to review.
Objašnjenje (HR)
Destrukturiranje jednom jasno pokazuje koja polja koristimo i ostatak koda cini kracim i laksim za review.
Exceptions / Tradeoffs (EN)
Keep direct property access when only one field is used once, or when destructuring would make a rename less clear.
Iznimke / Tradeoffi (HR)
Zadrzi izravan pristup svojstvu ako se koristi samo jedno polje jednom ili ako bi destrukturiranje ucinilo preimenovanje manje jasnim.