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
conditionalsdefaultsrobustness
Write conditionals so a missing value falls back to the default branch
Express product/variant checks as 'is one of the special cases' so an unset value defaults to the intended fallback, rather than 'equals the default'.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const isFinansavisen = product === ArticleProduct.finansavisen; |
| 2 | // breaks if product is undefined |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // anything that isn't a known special case falls back to FA |
| 2 | const isFinansavisen = |
| 3 | product !== ArticleProduct.kapital && product !== ArticleProduct.motor; |
Explanation (EN)
Objašnjenje (HR)