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

Comments

@Jakobud
Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Jul 18, 2017

@bcomnes

This comment has been minimized.

Copy link
Member

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 Jul 18, 2017

@Jakobud

This comment has been minimized.

Copy link
Author

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.
3 participants
You can’t perform that action at this time.