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: JavaScript / TypeScript
readabilitycontrol-flowswitch
Prefer switch/case over long if-else chains on one variable
When branching on the discrete values of a single variable, a switch/case reads more clearly than a chain of if/else-if comparisons.
PR: vinify-frontend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | if (param === 'manufacturer') return { ... }; |
| 2 | if (param === 'country') return { ... }; |
| 3 | if (param === 'grape') return { ... }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | switch (param) { |
| 2 | case 'manufacturer': return { ... }; |
| 3 | case 'country': return { ... }; |
| 4 | case 'grape': return { ... }; |
| 5 | default: return {}; |
| 6 | } |
Explanation (EN)
Objašnjenje (HR)