Skip to content

feat: add no-unrestricted-loop-in-serverless lint rule#56

Open
danielchen0 wants to merge 3 commits intomainfrom
danielchen0/no-unrestricted-loop-in-serverless
Open

feat: add no-unrestricted-loop-in-serverless lint rule#56
danielchen0 wants to merge 3 commits intomainfrom
danielchen0/no-unrestricted-loop-in-serverless

Conversation

@danielchen0
Copy link
Collaborator

Summary

  • Adds no-unrestricted-loop-in-serverless rule that detects unbounded loops (while(true), for(;;), while(1)) without a break or return in the loop body
  • These loops cause Vercel 300s timeouts in serverless functions — 21K+ timeouts/week in production
  • Smart about scope: doesn't count break inside nested loops/switches, or return inside nested arrow functions (e.g. .map() callbacks)
  • Allows loops that have proper exit conditions (break, return, bounded test)
  • Platform: backend only

Test plan

Scenario Expected
while (true) { await fetchData(); } (no break) Error flagged
for (;;) { await poll(); } (no break) Error flagged
while (1) { doWork(); } (no break) Error flagged
while (true) { if (done) break; } No error
while (true) { if (done) return data; } No error
for (let i = 0; i < 100; i++) { ... } No error
while (count < 10) { ... } No error
while (true) { for (...) { break; } } (break in nested loop) Error flagged (break doesn't exit outer)
while (true) { data.map(x => { return x; }) } (return in nested fn) Error flagged (return doesn't exit loop)

Detects unbounded loops (while(true), for(;;), while(1)) without break/return
in the loop body, which cause Vercel 300s timeouts in serverless functions.
Smart about nested loops and nested function returns. 21K+ timeouts/week.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant