Skip to content

Bug: no-loop-func errors on functions in the condition and not just the body #19120

Open
@LJNeon

Description

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

https://eslint.org/play/#eyJ0ZXh0IjoiY29uc3QgYXJyYXkgPSBbNSwgNywgOCwgM107XG5sZXQgaWR4ID0gMDtcblxud2hpbGUoYXJyYXkuc29tZShlbG0gPT4gZWxtID4gaWR4KSlcbiAgaWR4ICs9IDE7XG4iLCJvcHRpb25zIjp7InJ1bGVzIjp7Im5vLWxvb3AtZnVuYyI6WyJlcnJvciJdfSwibGFuZ3VhZ2VPcHRpb25zIjp7InBhcnNlck9wdGlvbnMiOnsiZWNtYUZlYXR1cmVzIjp7fX19fX0=

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusiondocumentationRelates to ESLint's documentationrepro:yesIssues with a reproducible exampleruleRelates to ESLint's core rules

    Type

    No type

    Projects

    • Status

      Ready to Implement

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions