No Await In Loop
Disallow await inside loops so sequential calls that should be parallelized with Promise.all() are caught early.
Summary
The no-await-in-loop rule reports any await expression found inside a loop. By default, all loop types are disallowed.
Use the configuration options to allow specific loop types (e.g., for...of for order-dependent iteration, while for pagination).
Why Use This Rule?
- Catches sequential network calls that should be parallelized for performance.
- Provides fine-grained control over which loop types are allowed to contain
await. - Keeps configuration centralized in the ESLint config rather than scattered across inline comments.
Examples
Configuration
Options
warning
ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.
| Option | Type | Default | Description |
|---|---|---|---|
allowFor | boolean | false | Allow await inside C-style for loops. |
allowForIn | boolean | false | Allow await inside for...in loops. |
allowForOf | boolean | false | Allow await inside for...of loops. |
allowWhile | boolean | false | Allow await inside while and do...while loops. |
ignoreFiles | string[] | [] | File patterns to skip. |
Autofix
Autofix is not available for this rule. Flagged code must be updated manually.
Troubleshooting
- Await in
for...ofis flagged — By default,allowForOfisfalse. Set it totrueif you want to allowawaitinfor...ofloops. - Warning fires outside a loop — The rule only checks
awaitinside loop bodies. If the warning appears elsewhere, theawaitmay be inside a nested loop you did not notice.