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

no-redeclare in a for loop scope seems wrong #955

Closed
Jakobud opened this issue Jul 18, 2017 · 3 comments
Closed

no-redeclare in a for loop scope seems wrong #955

Jakobud opened this issue Jul 18, 2017 · 3 comments

Comments

@Jakobud
Copy link

Jakobud commented Jul 18, 2017

It's pretty typical ES5 syntax to do this:

for (var index = 0; index < arrayOne.length; index++ ) {
  // code
}

for (var index = 0; index < arrayTwo.length; index++ ) {
  // code
}

The no-redeclare has an issue with this because index is being defined twice. This isn't a problem when using let but a lot of people still use ES5 on the frontend and Babel and Webpack are transpilling ot ES5 for frontend client side code as well.

Are there any thoughts on this? Obviously the solution is to declare index by itself at the top of the code, but I'm just looking to keep my code simple.

@yoshuawuyts
Copy link
Contributor

yoshuawuyts commented Jul 18, 2017 via email

@bcomnes
Copy link
Member

bcomnes commented Jul 18, 2017

Standard should lint the pre-compile side of babel. Machine generated code shouldn't require linting.

With hoisting the above code actually turns into:

var index
for (index = 0; index < arrayOne.length; index++ ) {
  // code
}

for (index = 0; index < arrayTwo.length; index++ ) {
  // code
}

The rule is to remind you of this, and to make sure you don't run into the pitfalls surrounding it.

fullsizerender 2
fullsizerender

Closing for now. Please let me know if there are undressed issues here and we can reopen.

@bcomnes bcomnes closed this as completed Jul 18, 2017
@Jakobud
Copy link
Author

Jakobud commented Jul 18, 2017

That makes sense. Thanks

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants