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
refactoringdrymaintainability
Extract inline workarounds into a reusable, parameterized utility
Inline quick-fix logic (like splitting a payload into fixed chunks) should be pulled into a named utility with parameterized sizes instead of being hardcoded at the call site.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | // TODO: split ids into 2 chunks, quick fix for too big request |
| 2 | const half = Math.ceil(ids.length / 2); |
| 3 | const a = await fetchByIds(ids.slice(0, half)); |
| 4 | const b = await fetchByIds(ids.slice(half)); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | function chunk<T>(items: T[], size: number): T[][] { |
| 2 | const out: T[][] = []; |
| 3 | for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size)); |
| 4 | return out; |
| 5 | } |
| 6 | const results = await Promise.all(chunk(ids, batchSize).map(fetchByIds)); |
Explanation (EN)
Objašnjenje (HR)