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: typescript
performancedryloopsdom
Avoid re-traversing data when the answer is already in hand
Reuse a collection you already iterated instead of querying the DOM or re-walking the structure a second time for the same fact.
PR: hegnar-components · org-mining-deep-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | const cells = Array.from(row.querySelectorAll('td, th')); |
| 2 | if (!hasHeader && row.querySelector('th')) hasHeader = true; // walks row again |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const cells = Array.from(row.querySelectorAll('td, th')); |
| 2 | if (!hasHeader && cells.some(c => c.tagName === 'TH')) hasHeader = true; // reuse |
Explanation (EN)
Objašnjenje (HR)