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 ruleP1universalStack: TypeScript
orderingdata-transformationcorrectness
Reorder filtered items to match the intended display order
Filtering a fixed-order config preserves config order, not the desired order; explicitly sort/map by the target order, ideally via a lookup map.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | // keeps config order, ignores visibleTabs order |
| 2 | const tabs = Object.values(config).filter(t => visibleTabs.includes(t.param)); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | const byParam = new Map(Object.values(config).map(t => [t.param, t])); |
| 2 | const tabs = visibleTabs.flatMap(p => { |
| 3 | const t = byParam.get(p); |
| 4 | return t ? [t] : []; |
| 5 | }); |
Explanation (EN)
Objašnjenje (HR)