feat(linter): implement eslint/no-loop-func rule#16830
feat(linter): implement eslint/no-loop-func rule#16830camc314 merged 6 commits intooxc-project:mainfrom
eslint/no-loop-func rule#16830Conversation
This rule disallows function declarations and expressions inside loop statements when they reference variables that may change across iterations. The rule detects: - Functions in loops referencing `var` variables declared in/around the loop - Functions referencing `let` variables declared outside the loop that are modified Safe patterns (not flagged): - `let`/`const` in for loop header (fresh binding per iteration) - `let`/`const` declared inside loop body (fresh binding per iteration) - Variables never modified - `const` and import bindings (immutable)
CodSpeed Performance ReportMerging #16830 will not alter performanceComparing Summary
Footnotes
|
|
Thanks for the review! I've run |
|
I'm currently refining some boundaries, and this PR will be updated again later. |
|
I've made significant improvements to better align with ESLint's semantics: Fixes:
Test coverage expanded to include:
|
All good, i pulled it down loclaly and found some issues, I can finish this off. |
7aa663a to
16e4e7f
Compare
|
Thank you so much for reviewing and offering to help finish this! Really appreciate it 🙏 |
Summary
Implements the ESLint
no-loop-funcrule which disallows function declarations and expressions inside loop statements when they reference variables that may change across iterations.What it detects:
varvariables declared in/around the loopletvariables declared outside the loop that are modified anywhereSafe patterns (not flagged):
let/constin for loop header (fresh binding per iteration)let/constdeclared inside loop body (fresh binding per iteration)constand import bindings (immutable)Examples
Incorrect:
Correct:
Test plan
cargo test -p oxc_linter -- no_loop_funcpassescargo clippypasses with no warnings