Skip to content

Fix loop over array to use for-of instead of for-in #10227

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

Merged
1 commit merged into from
Aug 10, 2016
Merged

Fix loop over array to use for-of instead of for-in #10227

1 commit merged into from
Aug 10, 2016

Conversation

ghost
Copy link

@ghost ghost commented Aug 9, 2016

I can't find any tests that this changes, but listFiles returns an array and fs.addFile expects a path, not an array index. Why is this not getting caught by our tests?

Also, @weswigham: I've been thinking we could add a lint rule where the object of a for-in loop would have to be of the Map type. What do you think?

@sandersn
Copy link
Member

sandersn commented Aug 9, 2016

👍

1 similar comment
@rbuckton
Copy link
Contributor

rbuckton commented Aug 9, 2016

👍

@weswigham
Copy link
Member

weswigham commented Aug 10, 2016

@Andy-MS Re: Lint rule: Seems a bit strong. I'd rather just forbid using a for-in loop where the thing being iterated over is of type string[] (thereby not triggering any syntax errors through misuse).

For the record, we use for-in loops 13 times in the checker, 5 times in the harness (4 after this change), and once in services. All 13 in the checker and once in the services layer are on maps (or things with indexers at least), but the same is not the case of our iteration in the harness.

TBH, we do use the construct infrequently enough that we could just forbid for-in completely and add exceptions around where keeping it is prudent for performance.

@ghost ghost merged commit bc5f41e into master Aug 10, 2016
@ghost ghost deleted the for_of branch August 10, 2016 13:07
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants