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: general
refactoringtestabilityseparation-of-concerns
Extract distinct loop bodies into named functions for testability
A long function that builds several independent collections in successive loops is easier to read and test when each loop becomes its own named function returning its slice of work.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | function purgeAll(req) { |
| 2 | for (const dim of AOI_DIMS) { /* build aoi ops */ } |
| 3 | for (const w of WIDTHS) { /* build resize ops */ } |
| 4 | // ... all inline |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | function aoiCoverVariations(baseUrl, aoi) { /* returns ops[] */ } |
| 2 | function resizeVariations(baseUrl) { /* returns ops[] */ } |
| 3 | function purgeAll(req) { |
| 4 | ops.push(...aoiCoverVariations(baseUrl, aoi), ...resizeVariations(baseUrl)); |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)