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

Proposed eslint rule additions #5456

Closed
14 of 16 tasks
mramato opened this issue Jun 12, 2017 · 14 comments
Closed
14 of 16 tasks

Proposed eslint rule additions #5456

mramato opened this issue Jun 12, 2017 · 14 comments

Comments

@mramato
Copy link
Contributor

mramato commented Jun 12, 2017

I did a pass on all available rules on http://eslint.org/docs/rules/ and picked out ones that we probably want in Cesium. We'll want to test these out one by one to make sure the rule isn't already handled by some of the other rules we are already using. We can turn a bunch of these on at once, assuming they don't require a bunch of code changes. Rules that do require a bunch of code changes should be done separately. I didn't include any style rules since they will be part of #5369. I also didn't include rules that were likely never to come up (for example explicitly disallowing eval).

Things we definitely want (almost all of these were part of jsHint and long when moved to eslint)

Things we probably want (Similar guidelines already exist in our documentation)

Node only (only apply to other Cesium ecosystem projects)

Still want to evaluate, but level of effort not worth it right now

@mramato
Copy link
Contributor Author

mramato commented Jun 12, 2017

If anyone has any thoughts on the above rules, or recommend additional rules that we should look into, please speak up. I'm hoping to have these rules added sometime over the next few weeks otherwise.

@ottaviohartman
Copy link
Contributor

@mramato can I get started on adding some of these to Cesium?

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 13, 2017

Things we definitely want (almost all of these were part of jsHint and long when moved to eslint)

👍

Things we probably want (Similar guidelines already exist in our documentation)

👍, except

class-methods-use-this

Does this apply to Cesium yet since it doesn't use class anywhere?

no-sequences

Generally, I would say yes, but I'm not sure we should commit to it since this allows for some nice graphics code like http://www.realtimerendering.com/blog/looping-through-polygon-edges/

Perhaps just enable it and see how many exceptions the current code base needs. If it is only a few, just stay with it.

Things we may want (cool ideas that might be overkill)
complexity

👎 This will be hard to reasonably enforce throughout the codebase, especially in areas of high algorithmic intensity. I expect there will be little return here and lots of frustration.

Node only (only apply to other Cesium ecosystem projects)

👍

Finally, please update the Coding Guide to be include anything new here. Throughout the Coding Guide, it would be useful to link to the specific ESLint doc as it often has more details and motivation than our guide.

@ottaviohartman
Copy link
Contributor

I've just been playing around to see how breaking these would be. no-use-before-define is the biggest I've tested with >900 errors.

@ottaviohartman
Copy link
Contributor

ottaviohartman commented Jun 16, 2017

Many PR's open, which include these rules:

  • guard-for-in
  • no-caller
  • no-floating-decimal
  • no-new
  • no-undef-init
  • default-case
  • no-alert
  • no-loop-func
  • no-implicit-globals
  • no-use-before-define

@ottaviohartman
Copy link
Contributor

consistent-return is proving difficult to implement. https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/Globe.js#L384, and many other functions rely on returning either a value or undefined.

Should I enable the rule and silence the errors inline?

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 16, 2017

Should I enable the rule and silence the errors inline?

Probably, unless there are dozens of these cases. We may come up with ideas to clean things up in the pull request.

@mramato
Copy link
Contributor Author

mramato commented Jun 22, 2017

Does this apply to Cesium yet since it doesn't use class anywhere?

I might have assumed it does since class is just a keyword, but I removed it from the list anyway after trying it out and seeing no results.

Generally, I would say yes, but I'm not sure we should commit to it since this allows for some nice graphics code like http://www.realtimerendering.com/blog/looping-through-polygon-edges/

The rule has a special case for for loops (which I agree is a common and often desired use of sequences). So this rule is exactly what we do in our own code already and will allow for the code you linked to.

@mramato
Copy link
Contributor Author

mramato commented Jun 22, 2017

I removed rules we either agreed worry worth it or were not what we ultimately wanted. I also moved no-shadow and valid-jsdoc to a different category because both require tons of changes. If I were starting a brand new code base, I would use them, but the way our code is right now isn't worth it until we have more time and decide we really want it.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 23, 2017

All sounds good.

@ottaviohartman
Copy link
Contributor

@mramato Pretty sure it's ready to be bumped to 2.0!

@mramato
Copy link
Contributor Author

mramato commented Jun 27, 2017

@mramato Pretty sure it's ready to be bumped to 2.0!

Open a PR to enable the 3 node rules, it most likely won't require any Cesium code changes (but update CHANGES.md to mention them), also bump the version. Once that's done, we'll merge and deploy and then we can update all of the other repositories.

@ottaviohartman
Copy link
Contributor

Ok! See #5540

@mramato
Copy link
Contributor Author

mramato commented Jun 27, 2017

2.0.0 has been published. Thanks @omh1280!

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

3 participants