feat: add no-unrestricted-loop-in-serverless lint rule#56
Conversation
|
Pushed an auto-fix commit to unblock the failing Lint & Format check (eslint @typescript-eslint/no-unnecessary-boolean-literal-compare in |
There was a problem hiding this comment.
Reviewed as steward. Approving — well-scoped.
Correctly handles:
while (true),while (1),for (;;),for (; true; )hasBreakOrReturnwalks up to confirm break/return belongs to this loop and not a nested loop or function
Non-blocking notes:
-
do { ... } while (true)is not caught. Easy add — samehasBreakOrReturncheck with aDoWhileStatementvisitor. -
throwis not counted as a termination path. A loop that exits viathrow new Error(...)will be flagged but is in fact bounded. Probably acceptable sincethrow-as-loop-exit is rare and arguably bad style. -
The platform tag is
backend— good. Consider whether long-running web workers or service workers (web platform) deserve coverage too. They're not strictly serverless but unbounded loops there will hang the worker. Could be a follow-up rule with broader scope, since the message specifically says 'serverless' which would be misleading if applied to workers.
OK to ship as-is.
|
Auto-fix: Lint & Format CI was failing on this rebase because README.md needed prettier formatting. Pushed prettier --write README.md as a follow-up commit. CI should go green on the next run. |
Rebased onto main to resolve conflicts after #51 merge.
7997ed4 to
7b6e531
Compare
Summary
no-unrestricted-loop-in-serverlessrule that detects unbounded loops (while(true),for(;;),while(1)) without abreakorreturnin the loop bodybreakinside nested loops/switches, orreturninside nested arrow functions (e.g..map()callbacks)backendonlyTest plan
while (true) { await fetchData(); }(no break)for (;;) { await poll(); }(no break)while (1) { doWork(); }(no break)while (true) { if (done) break; }while (true) { if (done) return data; }for (let i = 0; i < 100; i++) { ... }while (count < 10) { ... }while (true) { for (...) { break; } }(break in nested loop)while (true) { data.map(x => { return x; }) }(return in nested fn)