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).
backend ruleP1universalStack: typescript
validationenumsinput-handling
Validate enum/source params against an allowlist with a safe fallback
Check incoming string params against a known set of allowed values and fall back to a default rather than passing arbitrary input downstream.
PR: hegnar-ws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | const source = req.query.source ? [req.query.source] : DEFAULT; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const allowed = new Set(FEED_SOURCES); |
| 2 | const source = allowed.has(raw as FeedSource) ? [raw as FeedSource] : DEFAULT; |
Explanation (EN)
Objašnjenje (HR)