Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

one-var": [2, { initialized: "never" }] raised when multiple declarations exist in for loop #2505

Closed
feross opened this issue May 11, 2015 · 4 comments
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@feross
Copy link
Contributor

feross commented May 11, 2015

This is related to #2342.

I want to use the rule "one-var": [2, { initialized: "never" }]. It mostly works correctly, except it complains about:

var arr = [1, 2, 3];
for (var i = 0, len = arr.length; i < len; i++) {
  // ...
}

With this error: Split initialized 'var' declarations into multiple statements.

Is there some way to ignore statements inside for loops? I don't mind multiple declarations in there, but I do want to prevent this:

var i = 0, j = 5, k = 99;
@nzakas nzakas added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels May 12, 2015
@nzakas
Copy link
Member

nzakas commented May 12, 2015

We should probably just never warn about that for for loops.

@feross
Copy link
Contributor Author

feross commented May 12, 2015

Agreed.

@btmills
Copy link
Member

btmills commented May 12, 2015

Working on this.

nzakas added a commit that referenced this issue May 18, 2015
Fix: one-var exception for ForStatement.init (fixes #2505)
@Mouvedia
Copy link

@nzakas Could you add a ¶ about the fact that the rule ignores for loops on that page?

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

4 participants