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 ruleP2universalStack: typescript
readabilityperformanceconstants
Hoist invariant data structures out of the function body
When a constant lookup table or config object never changes per call, declare it at module scope instead of rebuilding it inside the function.
PR: hegnar-mws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | function runJob(name, fn) { |
| 2 | const levelMap = { debug: ['log','error'], info: ['log'], error: ['error'] }; |
| 3 | // ... uses levelMap |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const LEVEL_MAP = { debug: ['log','error'], info: ['log'], error: ['error'] }; |
| 2 |
|
| 3 | function runJob(name, fn) { |
| 4 | // ... uses LEVEL_MAP |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)