Standard: no-redeclare in a for loop scope seems wrong

Created on 18 Jul 2017  Â·  3Comments  Â·  Source: standard/standard

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.

Most helpful comment

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.

All 3 comments

Like you said, the solution is to declare index at the top of the file. I
also regularly run into this, but I don't mind it too much haha

On Tue, Jul 18, 2017, 21:26 Jake Wilson notifications@github.com wrote:

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.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/standard/standard/issues/955, or mute the thread
https://github.com/notifications/unsubscribe-auth/ACWlev204qYhyv8O4O2TbgKc4Drsj4Mbks5sPQb5gaJpZM4Obz8U
.

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.

That makes sense. Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jcalfee picture jcalfee  Â·  3Comments

Alexsey picture Alexsey  Â·  3Comments

davidjamesstone picture davidjamesstone  Â·  3Comments

gkatsanos picture gkatsanos  Â·  3Comments

BinaryBen picture BinaryBen  Â·  3Comments