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 semantic disambiguation around destructuring
If destructuring would collide with existing names, rename the surrounding locals based on their source or role, not with vague prefixes like current or updated.
Bad example
| 1 | const currentIncludeDividends = selectedPortfolio?.includeDividends ?? true; |
| 2 | const currentShowBenchmark = selectedPortfolio?.showBenchmark ?? false; |
| 3 |
|
| 4 | const { name, order, showBenchmark, includeDividends } = response; |
| 5 |
|
| 6 | setSelectedPortfolio(prevState => |
| 7 | prevState |
| 8 | ? { |
| 9 | ...prevState, |
| 10 | name, |
| 11 | order, |
| 12 | showBenchmark, |
| 13 | includeDividends, |
| 14 | } |
| 15 | : prevState |
| 16 | ); |
Explanation (EN)
The destructured response fields are fine, but the surrounding local names are vague. Prefixes like current do not explain where the value comes from or why it differs from the response value.
Objašnjenje (HR)
Destrukturirana response polja su u redu, ali su okolna lokalna imena nejasna. Prefiksi poput current ne objasnjavaju odakle vrijednost dolazi niti zasto se razlikuje od response vrijednosti.
Good example
| 1 | const selectedIncludeDividends = selectedPortfolio?.includeDividends ?? true; |
| 2 | const selectedShowBenchmark = selectedPortfolio?.showBenchmark ?? false; |
| 3 |
|
| 4 | const { name, order, showBenchmark, includeDividends } = response; |
| 5 |
|
| 6 | setSelectedPortfolio(prevState => |
| 7 | prevState |
| 8 | ? { |
| 9 | ...prevState, |
| 10 | name, |
| 11 | order, |
| 12 | showBenchmark, |
| 13 | includeDividends, |
| 14 | } |
| 15 | : prevState |
| 16 | ); |
| 17 |
|
| 18 | handleSettingsUpdate({ |
| 19 | includeDividends: !selectedIncludeDividends, |
| 20 | showBenchmark: selectedShowBenchmark, |
| 21 | }); |
Explanation (EN)
Keep destructured response fields in their canonical names so shorthand stays clean. Rename the other in-scope values semantically based on source or role, such as selected, previous, persisted, or draft.
Objašnjenje (HR)
Zadrzi destrukturirana response polja pod njihovim kanonskim imenima kako bi shorthand ostao cist. Ostale vrijednosti u scopeu preimenuj semanticki prema izvoru ili ulozi, npr. selected, previous, persisted ili draft.
Exceptions / Tradeoffs (EN)
Use current only when it is a real domain term, such as currentUser or currentRoute, not just as a generic collision workaround.
Iznimke / Tradeoffi (HR)
Koristi current samo kada je to stvarni domenski pojam, poput currentUser ili currentRoute, a ne kao genericko rjesenje za koliziju imena.