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).
Separate internal codes from localized labels
Do not drive business logic with translated display strings. Keep stable internal codes for comparisons and map them to localized labels at the UI boundary.
Bad example
| 1 | function isDividend(type: string) { |
| 2 | return type === 'utbytte'; |
| 3 | } |
| 4 |
|
| 5 | function getCashTypeLabel(type: string) { |
| 6 | return type === 'innskudd' ? 'Deposit' : 'Withdrawal'; |
| 7 | } |
Explanation (EN)
The same strings are serving both as domain identifiers and translated UI labels. That makes the code harder to understand outside one language context and couples logic changes to copy changes.
Objašnjenje (HR)
Isti stringovi služe i kao identifikatori domene i kao prevedene UI oznake. To otežava razumijevanje koda izvan jednog jezičnog konteksta i veže promjene logike uz promjene teksta.
Good example
| 1 | type CashType = 'deposit' | 'dividend' | 'withdrawal'; |
| 2 |
|
| 3 | const cashTypeLabels: Record<CashType, string> = { |
| 4 | deposit: 'Innskudd', |
| 5 | dividend: 'Utbytte', |
| 6 | withdrawal: 'Uttak', |
| 7 | }; |
| 8 |
|
| 9 | function isDividend(type: CashType) { |
| 10 | return type === 'dividend'; |
| 11 | } |
Explanation (EN)
The internal code stays stable and readable in business logic, while localization is handled separately where labels are rendered. This makes comparisons safer and translation changes cheaper.
Objašnjenje (HR)
Interni kod ostaje stabilan i čitljiv u poslovnoj logici, dok se lokalizacija rješava odvojeno na mjestu gdje se oznake renderiraju. Time su usporedbe sigurnije, a promjene prijevoda jeftinije.
Notes (EN)
This is especially important when the same domain value appears in APIs, analytics, persistence, and UI copy across multiple languages.
Bilješke (HR)
Ovo je posebno važno kada se ista domena vrijednost pojavljuje u API-jima, analitici, perzistenciji i UI copyju kroz više jezika.
Exceptions / Tradeoffs (EN)
Small one-off display-only mappings can stay inline, but the displayed label still should not become the source of truth for domain logic.
Iznimke / Tradeoffi (HR)
Mala jednokratna mapiranja samo za prikaz mogu ostati inline, ali prikazana oznaka i dalje ne bi smjela postati izvor istine za poslovnu logiku.