Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP2universalStack: typescript
switchenumstypesreadability
Reserve switch for enums or typed unions, not arbitrary strings
Use switch on enums or string-literal unions; for an open-ended string with one dominant default, prefer simpler branching.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codets
| 1 | function render(type: string) { |
| 2 | switch (type) { |
| 3 | case 'name': return <Name />; |
| 4 | case 'fullname': return <FullName />; |
| 5 | default: return <Plain />; |
| 6 | } |
| 7 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | type ColumnType = 'name' | 'fullname' | 'plain'; |
| 2 | function render(type: ColumnType) { |
| 3 | switch (type) { |
| 4 | case 'name': return <Name />; |
| 5 | case 'fullname': return <FullName />; |
| 6 | default: return <Plain />; |
| 7 | } |
| 8 | } |
Explanation (EN)
Objašnjenje (HR)