Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use a plain loop unless you actually await inside it
Use for await for asynchronous iteration or promised values; a synchronous loop body alone does not make it redundant.
Bad example
| 1 | for await (const item of items) { |
| 2 | const dto = mapItem(item); // nothing async here |
| 3 | results.push(dto); |
| 4 | } |
Explanation (EN)
For a synchronous iterable of plain values, async iteration adds unnecessary scheduling overhead.
Objašnjenje (HR)
Good example
| 1 | for (const item of items) { |
| 2 | results.push(mapItem(item)); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Inspect the iterable as well as the loop body: for await unwraps async iterator results and promise values even if the body itself is synchronous.
Exceptions / Tradeoffs (EN)
An async iterable with a synchronous body still requires asynchronous iteration. A regular for-of body can await sequential work; concurrency needs its own ordering and resource analysis.