Skip to content

prefer-const barks at looping variables #4088

@thefourtheye

Description

@thefourtheye

Let's say if I have code like this

for (let a of [1.3, 2, 3, 4]) {
  console.log(a);
}

enabling prefer-const rule errors out saying, error ais never modified, useconst instead prefer-const. But if we change that let to const, the value will never change in the loop. Note that this happens only in sloppy and strong mode. In strict mode const works fine. (All these are tested with Node.js v4.1.2).

Is it really safe/okay to suggest changing loop variable to const?

Related: nodejs/node#3152 (comment)

ESLint version: 0.24.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    archived due to ageThis issue has been archived; please open a new issue for any further discussiontriageAn ESLint team member will look at this issue soon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions