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

Disable for...of by default, rewrite cases where it matters #12198

Merged
merged 3 commits into from Feb 9, 2018

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Feb 9, 2018

for...of introduces a dependency on Symbol and Symbol.iterator (and bloated code too, with try / catch in a potentially very hot DEV path). We accidentally merged that in #10783.

I'm adding this rule so we can be more vigilant. You can ignore it for build and other scripts but please don't ignore it in the source.

for (const key of Object.keys(fragment.props)) {
const keys = Object.keys(fragment.props);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly saying this is the only case where it matters. But I figured changing TestRenderer code doesn't hurt too.

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks Dan.

@gaearon gaearon merged commit 467b103 into facebook:master Feb 9, 2018
@@ -11,6 +11,7 @@ module.exports = {

plugins: [
'jest',
'no-for-of-loops',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need a whole plugin for this? You can use no-restricted-syntax to block for..of loops with a custom message.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn’t know that. Happy to take a PR.

SadPandaBear pushed a commit to SadPandaBear/react that referenced this pull request Feb 15, 2018
…#12198)

* Add no-for-of lint rule

* Ignore legit use cases of for..of

* Rewrite for..of in source code
rhagigi pushed a commit to rhagigi/react that referenced this pull request Apr 19, 2018
…#12198)

* Add no-for-of lint rule

* Ignore legit use cases of for..of

* Rewrite for..of in source code
NMinhNguyen referenced this pull request in enzymejs/react-shallow-renderer Jan 29, 2020
* Add no-for-of lint rule

* Ignore legit use cases of for..of

* Rewrite for..of in source code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants