Bug: no-loop-func
errors on functions in the condition and not just the body #19120
Open
Description
opened on Nov 11, 2024
Environment
Node version: v22.11.0
npm version: v10.9.0
Local ESLint version: v9.14.0 (Currently used)
Global ESLint version: Not found
Operating System: linux 6.8.0-48-generic
What parser are you using?
Default (Espree)
What did you do?
Configuration
export default [{rules: {"no-loop-func": 2}}];
const array = [5, 7, 8, 3];
let idx = 0;
while(array.some(elm => elm > idx))
idx += 1;
What did you expect to happen?
No error reported as there are no unsafe references.
What actually happened?
An error was reported, citing the arrow function inside the condition of the while statement.
Link to Minimal Reproducible Example
Participation
- I am willing to submit a pull request for this issue.
Additional comments
Functions inside of the condition are evaluated once per loop and are thus safe to reference variables that are modified. This is a false positive.
Metadata
Assignees
Labels
Type
Projects
Status
Ready to Implement
Activity