Node: Create Lint Rule to avoid `let` in `for` loops

Created on 12 Oct 2016  路  7Comments  路  Source: nodejs/node

In #8873 we removed let from for loops due to potential de-opts. It would be nice to have a linting rule to avoid more instances leaking into the code base.

For context, our other lint rules can be found in tools/eslint-rules

good first issue help wanted mentor-available test tools

All 7 comments

Hi, I'd like to give this a shot as a contribution!

go for it @jessicaquynh

Let me know if you need any help!

@Trott may be a good resource as well, he's written quite a few of the lint rules

@TheAlphaNerd will do! Thank you, and I will reach out to @Trott for good resources and paradigms, thanks!

I've opened up a PR on this issue for review.

I am unsure if it was necessary, but I included within the lint, definitions for forIn and forOf as well. I would really appreciate input from @TheAlphaNerd and @Trott whenever you have got time! Thanks :)

So after making the var changes to the functions in the lib/ directory, I am coming across a redeclare error on the iterator variable ('i' is already defined no-redeclare) in multiple instances.

I am certain it's because of the scope differences between let and var.

I am unsure how to approach resolving this. I could rename all the loop variables, but I don't think that's good convention since some files have more than ten for-loops. Would anyone have any recommended solutions? @TheAlphaNerd @Trott

@jessicaquynh I don't think there should be any changes at all to the lib directory with this change other than adding one line to .eslintrc. There are no violations of this lint rule in the lib directory so the files there can be left unchanged (other than the .eslintrc file).

@Trott Ah! I understand my misstep now. I was running the test with the rule in the node/.eslintrc instead of the one in lib which cropped up those errors. Thank you for the clarification.

Was this page helpful?
0 / 5 - 0 ratings