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).
Don't repeat the category in an identifier the context already implies
Within a collection that is already scoped to a type (an icon set, a colors map, an enum), don't suffix each member with that type. The context supplies it; the suffix is redundant.
Bad example
| 1 | const icons = { |
| 2 | 'home-icon': '<svg/>', |
| 3 | 'search-icon': '<svg/>', |
| 4 | 'user-icon': '<svg/>', |
| 5 | }; |
| 6 |
|
| 7 | use('home-icon'); |
Explanation (EN)
Every key repeats -icon even though the object is already named icons. The suffix carries no information and lengthens every reference.
Objašnjenje (HR)
Svaki kljuc ponavlja -icon iako je objekt vec nazvan icons. Sufiks ne nosi informaciju i produljuje svaku referencu.
Good example
| 1 | const icons = { |
| 2 | home: '<svg/>', |
| 3 | search: '<svg/>', |
| 4 | user: '<svg/>', |
| 5 | }; |
| 6 |
|
| 7 | use('home'); |
Explanation (EN)
The enclosing name (icons) already tells you what these are, so the bare keys read cleaner and references are shorter.
Objašnjenje (HR)
Obuhvatni naziv (icons) vec govori sto su to, pa se goli kljucevi citaju cisce, a reference su krace.
Exceptions / Tradeoffs (EN)
Keep the suffix when identifiers leave their scope and become ambiguous on their own (e.g. global DOM ids that must stay unique and self-describing).
Iznimke / Tradeoffi (HR)
Zadrzi sufiks kada identifikatori napustaju svoj scope i postanu dvosmisleni sami za sebe (npr. globalni DOM id-evi koji moraju ostati jedinstveni i samoopisni).