| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
Thanks for the PR! This generally looks good to me, aside from one small change.
Sorry, something went wrong.
There was a problem hiding this comment.
The implementation for ForStatement nodes looks good. I think checking ForInStatement and ForOfStatement nodes is a good idea, but I don't think this rule is correctly checking those nodes at the moment, since they don't have an init property. Instead, I think you would want to check the left property.
Sorry, something went wrong.
There was a problem hiding this comment.
Ah that's right. Thank you for pointing that out! I feel silly about that one. I will update the file.
Sorry, something went wrong.
|
So it looks like you will need to add an entry into the .eslintrc if you want to get the rule to work You can check http://eslint.org/docs/developer-guide/working-with-rules#runtime-rules for more details edit: you may want to alternatively put it in lib/.eslintrc if we only want to test the lib once the rule is added you will notice TONS of failures in our test / benchmark directories. You will likely want to fix all of those in a separate commit. Once you have done that you will want to rebase the rule to after the changes, so that the repo will always be in a working state. $ git rebase -i HEAD~5 # start and interactive rebase for the last 5 commits this will give you a list of commits, you can then move the commits around in that list, save, and close. This will edit the history You will likely want to compile and test locally to make sure it works. $ ./configure $ make -j8 $ make test Let me know if you have any questions 😄 |
Sorry, something went wrong.
There was a problem hiding this comment.
I don't think that we need to run both checks on every iteration. It may be better to have a bit of repeated code instead of doing an extra evaluation on every for loop.
Sorry, something went wrong.
There was a problem hiding this comment.
That makes a lot of sense! I will update the test and add it to the .eslintrc. I was wondering if it would be more appropriate to report an error or simply a warning on the rule?
Sorry, something went wrong.
There was a problem hiding this comment.
I'd go with error.
Sorry, something went wrong.
There was a problem hiding this comment.
@thealphanerd okay! thank you
Sorry, something went wrong.
|
Is there any context on why to avoid let in loops? |
Sorry, something went wrong.
There was a problem hiding this comment.
Use checkForLet (point-free style). (node) => checkForLet(node) is a unnecessary wrapper.
Sorry, something went wrong.
There was a problem hiding this comment.
@princejwesley I think this was based on the way a number of other lint rules have been designed
@Trott can you chime in?
Sorry, something went wrong.
There was a problem hiding this comment.
I think the suggestion from @princejwesley is a good one. The other tests that use a wrapper are also passing context because it is out of scope the way they are written, but not this one.
Sorry, something went wrong.
There was a problem hiding this comment.
Thank you @princejwesley ! I've learned (more formally) about tacit programming from this review. :)
Sorry, something went wrong.
|
@cosmosgenius See #8637. At the moment, var has better performance than let. |
Sorry, something went wrong.
|
Nit: To be consistent with naming conventions in ESLint itself, maybe change the name of the rule from restrict-let-in-for-loops to no-let-in-for-loops or no-let-in-for-declarations or something like that. |
Sorry, something went wrong.
There was a problem hiding this comment.
Nit: Maybe specify that it's just the declarations (or whatever the right terminology is)? I think this makes it sound like we're forbidding it in the body as well, but we're not.
Sorry, something went wrong.
There was a problem hiding this comment.
from the mdn docs
I think it would make sense to refer to it as the prohibit the use of let in for loop initialization
Sorry, something went wrong.
There was a problem hiding this comment.
@Trott Definitely agree with you. I changed the wording to have Prohibit the use ofletas the loop variable in the initialization of for, and the left-hand iterator in forIn and forOf loops. Which may be too verbose? I just missed @thealphanerd comment before changing this. Let me know what you think!
Sorry, something went wrong.
There was a problem hiding this comment.
I'm OK with comments being verbose. 👍
Sorry, something went wrong.
|
Aside/question: I know there are benchmarks that show for (let i=0; i<j; i++) is slower than using var. And @ofrobots warns against that usage, I believe. But is it also the case for let in for loop using in and/or of as well? |
Sorry, something went wrong.
There was a problem hiding this comment.
Only change I'd want to see is reporting the right column, although honestly, if that is onerous or controversial, this can land as is.
Sorry, something went wrong.
There was a problem hiding this comment.
Nit: In my opinion, this ends up reporting the wrong column. It indicates the issue is in the column where for starts, but it should really report the column where let occurs. Is it possible to fix that? Maybe instead of returning a boolean, testForLoop() and friends can return the offending node and that can be passed to context.report() rather than the for node?
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks @Trott, with the review given from @thealphanerd, I broke up this function and returned the offensive node as you suggested to report the correct column!
Sorry, something went wrong.
|
Oh, and +1 to adding it to lib/.eslintrc only. |
Sorry, something went wrong.
|
thanks for the review @Trott @jessicaquynh if you move the rule to the lib/ folder you should no longer see any of the errors. Please let me know if you need any support on this at all. |
Sorry, something went wrong.
|
LGTM. |
Sorry, something went wrong.
Sorry, something went wrong.
|
nit: the subsystem should be tools, not eslint, in the commit message. Thanks for the patience through the review process @jessicaquynh 🎉 |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
This adds a new ESLint tool to check for let declarations within the for, forIn, forOf expressions. Fixes: nodejs#9045 Ref: nodejs#8873
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
This adds a new ESLint tool to check for let declarations within the for, forIn, forOf expressions. Fixes: nodejs#9045 Ref: nodejs#8873 PR-URL: nodejs#9049 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This adds a new ESLint tool to check for let declarations within the for, forIn, forOf expressions. Fixes: #9045 Ref: #8873 PR-URL: #9049 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This adds a new ESLint tool to check for let declarations within the for, forIn, forOf expressions. Fixes: #9045 Ref: #8873 PR-URL: #9049 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This adds a new ESLint tool to check for let declarations within the for, forIn, forOf expressions. Fixes: nodejs#9045 Ref: nodejs#9553 Ref: nodejs#8873 PR-URL: nodejs#9049 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This adds a new ESLint tool to check for let declarations within the for, forIn, forOf expressions. Fixes: #9045 Ref: #9553 Ref: #8873 PR-URL: #9049 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
| Back | FazBrowse Home | New Git URL |
Checklist
Affected core subsystem(s)
Tools.
Description of change
This adds a new ESLint tool to check for let declarations within the for, forIn, forOf expressions.
Fixes: #9045
Ref: #8873