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

Remove for of loop from sim code #972

Closed
5 tasks done
zepumph opened this issue Dec 11, 2018 · 28 comments
Closed
5 tasks done

Remove for of loop from sim code #972

zepumph opened this issue Dec 11, 2018 · 28 comments

Comments

@zepumph
Copy link
Member

zepumph commented Dec 11, 2018

It looks like babel transpiles this into using Symbol and expects a polyfill. We don't do polyfill that right now. On top of that @jonathanolson says that forEach loops are faster even with the closure. As a result we should convert usages to that, and when necessary use the traditional for (let i=0; i<length; i++).

I see 75 usages of for \( let \b[A-z]*\b of, though many can stick around because they aren't in sim code. Assigning to responsible devs of these repos.

  • friction
  • wave interference
  • fractions-common
  • gravity force lab
  • Enumeration
@samreid
Copy link
Member

samreid commented Dec 11, 2018

See also phetsims/wave-interference#223

zepumph added a commit to phetsims/friction that referenced this issue Dec 11, 2018
@zepumph zepumph removed their assignment Dec 11, 2018
samreid added a commit to phetsims/phet-core that referenced this issue Dec 11, 2018
jonathanolson added a commit to phetsims/fractions-common that referenced this issue Dec 11, 2018
@jonathanolson jonathanolson removed their assignment Dec 11, 2018
mbarlow12 added a commit to phetsims/gravity-force-lab that referenced this issue Dec 12, 2018
@samreid
Copy link
Member

samreid commented Dec 12, 2018

I recommend to add a lint rule so this syntax doesn't accidentally sneak in. However, once we introduce a lint rule for this, we will need to address the 55 other occurrences of for...in that occur in non-sim code. We can convert them to forEach or mark them as eslint-disable-line.

samreid added a commit to phetsims/gravity-force-lab that referenced this issue Dec 12, 2018
samreid added a commit to phetsims/perennial that referenced this issue Dec 12, 2018
@samreid
Copy link
Member

samreid commented Dec 12, 2018

Pushed new lint rule that prevents for...of. This will prevent it from leaking into our sims, and will help encourage us to use consistent style across sims + tools. I suspect some team members may prefer to use for...of in tools without having to specify // eslint-disable-line no-restricted-syntax, but it would seem unfortunate to divide our linting rules. May require further discussion.

@jonathanolson
Copy link
Contributor

I suspect some team members may prefer to use for...of in tools without having to specify // eslint-disable-line no-restricted-syntax, but it would seem unfortunate to divide our linting rules.

Definitely don't want to have to provide an eslint disable for most of my for-loops in Node.js code.

How about we deliberately have separate Node.js and browser rules? For example, you never want to reference a global window in Node.js since it doesn't exist. But presumably we don't want to have an eslint line disable comment for every usage of window, etc. (or would you feel otherwise?)

@jessegreenberg
Copy link

@pixelzoom
Copy link
Contributor

pixelzoom commented Dec 13, 2018

12/13/18 dev meeting: @zepumph will investigate splitting into server (Node) vs browser lint rules.

@zepumph
Copy link
Member Author

zepumph commented Jan 17, 2019

I believe everything has been done for this issue. Further work in linked issues above.

Mighty inconvenient, but I guess we'll have to live with it.

@pixelzoom as for the error you pointed out, I have two thoughts.

  1. The chipper lint config doesn't change all the time, but if we added a lint rule that the old rc of BCE failed, then it would be reasonable to think that you would have to checkout old chipper in order to get lint to pass. To me finding a bug because some shas are on a branch and others aren't comes with the territory, though I do admit that lint wasn't failing for those cases, and not is.
  2. I think I have a potential solution, though it isn't ideal. The error is because we have moved to a tree structure in eslint configs, so if the linter looks at parent directories until it finds an eslint config file, for most repos, that is in the package.json. What you can do is add .eslintrc.js to the directory that contains all of the phet repos, so the parent to chipper and sims and whatnot, and have its contents look like:
module.exports = {
  extends: './chipper/eslint/.eslintrc.js',
};

Then the linter will fall back to this if no config is found in a given repo. I tested this by adding the file to my repo parent dir, and then checking out BCE 1.2. grunt lint is successful (though note it fails lint because of added lint rules in the past few weeks).

@pixelzoom let me know if this is something you are interested in pursuing as a workaround. Otherwise feel free to close.

@zepumph zepumph assigned pixelzoom and unassigned samreid and zepumph Jan 17, 2019
@pixelzoom
Copy link
Contributor

Thanks for investigating options.

I'll live with having to checkout-shas in order to cherry pick.

Closing.

samreid pushed a commit to phetsims/phet-info that referenced this issue Apr 23, 2022
zepumph added a commit to phetsims/perennial that referenced this issue Jul 21, 2022
zepumph added a commit to phetsims/perennial that referenced this issue Jul 21, 2022
zepumph added a commit to phetsims/perennial that referenced this issue Jul 21, 2022
zepumph added a commit to phetsims/perennial that referenced this issue Jul 21, 2022
samreid pushed a commit to phetsims/perennial that referenced this issue Oct 17, 2024
samreid pushed a commit to phetsims/perennial that referenced this issue Oct 17, 2024
samreid pushed a commit to phetsims/perennial that referenced this issue Oct 17, 2024
samreid pushed a commit to phetsims/perennial that referenced this issue Oct 17, 2024
zepumph pushed a commit to phetsims/perennial that referenced this issue Oct 22, 2024
zepumph added a commit to phetsims/perennial that referenced this issue Oct 22, 2024
zepumph added a commit to phetsims/perennial that referenced this issue Oct 22, 2024
zepumph added a commit to phetsims/perennial that referenced this issue Oct 22, 2024
zepumph added a commit to phetsims/perennial that referenced this issue Oct 22, 2024
zepumph added a commit to phetsims/perennial that referenced this issue Oct 22, 2024
zepumph added a commit to phetsims/perennial that referenced this issue Oct 22, 2024
samreid pushed a commit to phetsims/perennial that referenced this issue Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants