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

Investigate ESLint #235

Closed
samreid opened this issue Aug 7, 2015 · 54 comments
Closed

Investigate ESLint #235

samreid opened this issue Aug 7, 2015 · 54 comments

Comments

@samreid
Copy link
Member

samreid commented Aug 7, 2015

In #195 we determined that JSHint does not provide support new linting rules or tests. However, it seems like https://github.com/eslint/eslint is becoming very popular and it looks like it has backward support for JSHint rules and the ability to add your own rules.

If we are going to be adding more of our lint style rules like in #195 then we may want to invest in ESLint. No plans to look into it now but wanted to bring it up for future investigation.

@samreid
Copy link
Member Author

samreid commented Aug 13, 2015

@ariel-phet suggested to defer to an upcoming meeting for scheduling work on this.

@samreid
Copy link
Member Author

samreid commented Aug 18, 2015

ESLint will probably take longer to process than JSHint since it produces an AST for each file.

@samreid
Copy link
Member Author

samreid commented Aug 18, 2015

I'm interested to investigate this, but don't think I'll have time until after Bending Light is published.

@pixelzoom said this may not be worth the effort at the moment, may be more important if/when we re-engage with 3rd parties.

@samreid suggested investigating this when someone is reviewing a simulation and wishing for better automated support.

@samreid
Copy link
Member Author

samreid commented Sep 14, 2015

ESLint 1.4.0 was released recently, with support for cached results which will improve speed significantly (linting only occurs on files that have changed since last time of lint). Come to think of it, this may even be a speed improvement over our jshint process. So my concerns regarding performance are significantly allayed.

http://eslint.org/blog/2015/09/eslint-v1.4.0-released/

@samreid
Copy link
Member Author

samreid commented Sep 30, 2015

I've been enjoying the IDEA jshint plugin and noticed it has a similar ESLint plugin. It would be very nice to catch ESLint issues in the IDE while coding.

Thinking about how to approach ESLint--we wouldn't have to immediately bail on jshint and jump ship to ESLint, we could add an eslint phase to our existing process that only checks for specific things (that we miss with jshint).

I just saw another file where the constructor name didn't match the filename and it confused me for a bit. This seems like a natural thing to look for in ESLint--if there are any constructor functions, make sure at least one matches the filename. And I confirmed that ESLint context provides filename.

@samreid
Copy link
Member Author

samreid commented Oct 1, 2015

@jbphet @jonathanolson say ok to investigate ESLint as an add-on step as long as it doesn't slow down the build.

@samreid samreid self-assigned this Oct 1, 2015
@samreid
Copy link
Member Author

samreid commented Oct 1, 2015

Assigned to myself (low priority) to take a look and see how this would impact our toolchain.

@samreid
Copy link
Member Author

samreid commented Oct 2, 2015

Testing for ESLint performance, using 3 eslint tasks in bending-light I see:

time grunt lint-all // 14.358s
time grunt eslint-all // 14.634s (first time)
time grunt eslint-all // 1.886s (second time, with cache)

After introducing an error into one file (3 missing ;):
time grunt eslint-all // 1.928s
time grunt lint-all // 14.072s

So a cached eslint with a small number of modified files takes about 14% of the time of running jshint. Without caching (or if all files changed) the times seem comparable.

A huge difference in the formatting:
image

vs

image

For me the eslint output is far easier to grok.

@samreid
Copy link
Member Author

samreid commented Oct 2, 2015

I'm elated at the idea of a linting step that takes 2 seconds instead of 14 seconds. Elated enough to abandon jshint completely and replace it with eslint? Perhaps.

@samreid
Copy link
Member Author

samreid commented Oct 2, 2015

Guess who wouldn't have to deal with grunt --lint=false anymore. This guy:
image

@samreid
Copy link
Member Author

samreid commented Oct 2, 2015

Checking for the cost (in time) of adding a cached eslint step to our existing process (default grunt, which includes jshint+requirejs+etc)

with eslint: 51.014s
without eslint: 51.344s

So it looks like the time added by a cached eslint is in the noise.

@samreid
Copy link
Member Author

samreid commented Oct 2, 2015

For reference, here are the default eslinting rules our code doesn't follow:

/Users/samreid/github/axon/js/Property.js
  262:44  error  Unexpected console statement  no-console

/Users/samreid/github/axon/js/PropertySet.js
  72:22  error  Unexpected console statement  no-console

/Users/samreid/github/chipper/js/common/getDeployConfig.js
  50:32  error  "process" is not defined  no-undef

/Users/samreid/github/chipper/js/grunt/Gruntfile.js
  22:5   error  "_" is read only       no-undef
  92:43  error  Empty block statement  no-empty

/Users/samreid/github/chipper/js/grunt/checkoutShas.js
  38:28  error  Strings must use singlequote  quotes

/Users/samreid/github/chipper/js/grunt/createDependenciesJSON.js
  18:5  error  "_" is read only  no-undef

/Users/samreid/github/chipper/js/grunt/createSim.js
  82:63  error  Empty block statement  no-empty

/Users/samreid/github/chipper/js/grunt/getBuildConfig.js
   39:5   error  "_" is read only          no-undef
  254:43  error  "process" is not defined  no-undef

/Users/samreid/github/chipper/js/grunt/getGruntConfig.js
  11:5  error  "_" is read only  no-undef

/Users/samreid/github/chipper/js/grunt/getThirdPartyLibEntries.js
  16:5  error  "_" is read only  no-undef

/Users/samreid/github/chipper/js/grunt/reportMedia.js
  42:19  error  "process" is not defined  no-undef

/Users/samreid/github/chipper/js/grunt/reportThirdParty.js
  56:21  error  "process" is not defined  no-undef

/Users/samreid/github/chipper/js/grunt/reportUnusedMedia.js
  28:19  error  "process" is not defined  no-undef

/Users/samreid/github/chipper/js/requirejs-plugins/image.js
  46:22  error  Empty block statement  no-empty

/Users/samreid/github/chipper/js/requirejs-plugins/mipmap.js
  134:22  error  Empty block statement  no-empty

/Users/samreid/github/chipper/js/requirejs-plugins/registerLicenseEntry.js
  56:9  error  Unexpected console statement  no-console

/Users/samreid/github/chipper/js/requirejs-plugins/string.js
  193:19  error  Unexpected console statement  no-console
  193:32  error  Strings must use singlequote  quotes

/Users/samreid/github/dot/js/Complex.js
  77:14  error  Strings must use singlequote  quotes
  77:36  error  Strings must use singlequote  quotes
  77:52  error  Strings must use singlequote  quotes

/Users/samreid/github/dot/js/Dimension2.js
  25:14  error  Strings must use singlequote  quotes
  25:33  error  Strings must use singlequote  quotes
  25:55  error  Strings must use singlequote  quotes

/Users/samreid/github/dot/js/LUDecomposition.js
  158:26  error  Strings must use singlequote  quotes
  170:26  error  Strings must use singlequote  quotes
  173:26  error  Strings must use singlequote  quotes

/Users/samreid/github/dot/js/Matrix.js
  323:28  error  Strings must use singlequote  quotes
  398:26  error  Strings must use singlequote  quotes
  403:20  error  Strings must use singlequote  quotes
  404:17  error  Strings must use singlequote  quotes
  404:52  error  Strings must use singlequote  quotes
  404:86  error  Strings must use singlequote  quotes
  407:44  error  Strings must use singlequote  quotes
  409:19  error  Strings must use singlequote  quotes
  486:24  error  Strings must use singlequote  quotes
  513:24  error  Strings must use singlequote  quotes

/Users/samreid/github/dot/js/Matrix3.js
  983:7  error  Unexpected console statement  no-console

/Users/samreid/github/dot/js/Matrix4.js
  527:27  error  Strings must use singlequote  quotes
  527:46  error  Strings must use singlequote  quotes
  527:65  error  Strings must use singlequote  quotes
  527:84  error  Strings must use singlequote  quotes
  528:27  error  Strings must use singlequote  quotes
  528:46  error  Strings must use singlequote  quotes
  528:65  error  Strings must use singlequote  quotes
  528:84  error  Strings must use singlequote  quotes
  529:27  error  Strings must use singlequote  quotes
  529:46  error  Strings must use singlequote  quotes
  529:65  error  Strings must use singlequote  quotes
  529:84  error  Strings must use singlequote  quotes
  530:27  error  Strings must use singlequote  quotes
  530:46  error  Strings must use singlequote  quotes
  530:65  error  Strings must use singlequote  quotes
  535:26  error  Strings must use singlequote  quotes

/Users/samreid/github/dot/js/Permutation.js
   83:28  error  Strings must use singlequote  quotes
   83:66  error  Strings must use singlequote  quotes
  124:14  error  Strings must use singlequote  quotes
  124:40  error  Strings must use singlequote  quotes
  124:49  error  Strings must use singlequote  quotes
  130:5   error  Unexpected console statement  no-console
  133:5   error  Unexpected console statement  no-console
  135:5   error  Unexpected console statement  no-console
  137:5   error  Unexpected console statement  no-console

/Users/samreid/github/dot/js/QRDecomposition.js
  139:26  error  Strings must use singlequote  quotes
  142:26  error  Strings must use singlequote  quotes

/Users/samreid/github/dot/js/Range.js
  68:14   error  Strings must use singlequote  quotes
  68:42   error  Strings must use singlequote  quotes
  68:63   error  Strings must use singlequote  quotes
  68:102  error  Strings must use singlequote  quotes

/Users/samreid/github/dot/js/Ray2.js
  36:41  error  Strings must use singlequote  quotes

/Users/samreid/github/dot/js/Ray3.js
  37:36  error  Strings must use singlequote  quotes

/Users/samreid/github/dot/js/Vector2.js
  119:26  error  Strings must use singlequote  quotes
  289:26  error  Strings must use singlequote  quotes
  334:24  error  Strings must use singlequote  quotes
  334:79  error  Strings must use singlequote  quotes

/Users/samreid/github/dot/js/Vector3.js
   98:26  error  Strings must use singlequote  quotes
  162:14  error  Strings must use singlequote  quotes
  162:36  error  Strings must use singlequote  quotes
  162:52  error  Strings must use singlequote  quotes
  162:68  error  Strings must use singlequote  quotes
  248:26  error  Strings must use singlequote  quotes
  285:24  error  Strings must use singlequote  quotes
  285:79  error  Strings must use singlequote  quotes

/Users/samreid/github/dot/js/Vector4.js
   88:26  error  Strings must use singlequote  quotes
  148:14  error  Strings must use singlequote  quotes
  148:36  error  Strings must use singlequote  quotes
  148:52  error  Strings must use singlequote  quotes
  148:68  error  Strings must use singlequote  quotes
  148:84  error  Strings must use singlequote  quotes
  229:26  error  Strings must use singlequote  quotes
  255:24  error  Strings must use singlequote  quotes
  255:79  error  Strings must use singlequote  quotes

/Users/samreid/github/joist/js/PhetMenu.js
  239:11  error  Unexpected console statement  no-console

/Users/samreid/github/joist/js/Profiler.js
  58:25  error  Strings must use singlequote  quotes

/Users/samreid/github/joist/js/Sim.js
  466:24  error  Strings must use singlequote                            quotes
  636:13  error  Redundant double negation in an if statement condition  no-extra-boolean-cast

/Users/samreid/github/joist/js/SimJSON.js
  30:18  error  Strings must use singlequote  quotes

/Users/samreid/github/joist/js/UpdateCheck.js
  121:15  error  Unexpected console statement  no-console
  134:17  error  Unexpected console statement  no-console

/Users/samreid/github/phet-core/js/loadScript.js
  42:31  error  Strings must use singlequote  quotes
  42:55  error  Strings must use singlequote  quotes

/Users/samreid/github/phet-core/js/phetAllocation.js
  44:11  error  Unexpected console statement  no-console

/Users/samreid/github/phetcommon/js/model/SphereBucket.js
  63:7  error  Unexpected console statement  no-console

/Users/samreid/github/scenery/js/debug/DebugContext.js
  28:5  error  Unexpected console statement  no-console

/Users/samreid/github/scenery/js/display/GreedyStitcher.js
  124:7  error  Unexpected constant condition  no-constant-condition
  325:9  error  Unexpected constant condition  no-constant-condition

/Users/samreid/github/scenery/js/display/PixiBlock.js
  111:7  error  Unexpected console statement  no-console

/Users/samreid/github/scenery/js/display/webgl/ColorTriangleBufferData.js
  86:9  error  Unexpected console statement  no-console

/Users/samreid/github/scenery/js/input/Input.js
  360:9   error  Unexpected constant condition  no-constant-condition
  399:9   error  Unexpected constant condition  no-constant-condition
  407:9   error  Unexpected constant condition  no-constant-condition
  575:18  error  Unexpected console statement   no-console
  576:15  error  Unexpected console statement   no-console
  593:18  error  Unexpected console statement   no-console
  594:15  error  Unexpected console statement   no-console
  602:29  error  Unexpected console statement   no-console
  603:15  error  Unexpected console statement   no-console
  613:18  error  Unexpected console statement   no-console
  614:15  error  Unexpected console statement   no-console
  631:18  error  Unexpected console statement   no-console
  632:15  error  Unexpected console statement   no-console
  775:13  error  Unexpected console statement   no-console

/Users/samreid/github/scenery/js/nodes/Image.js
  69:30  error  Strings must use singlequote  quotes

/Users/samreid/github/scenery/js/nodes/Node.js
   854:42  error  Empty block statement         no-empty
  2416:33  error  Strings must use singlequote  quotes
  3487:22  error  Empty block statement         no-empty

/Users/samreid/github/scenery/js/nodes/Text.js
  903:68  error  Empty block statement  no-empty

/Users/samreid/github/scenery/js/util/Color.js
  475:38   error  Strings must use singlequote  quotes
  475:55   error  Strings must use singlequote  quotes
  475:72   error  Strings must use singlequote  quotes
  475:89   error  Strings must use singlequote  quotes
  475:106  error  Strings must use singlequote  quotes

/Users/samreid/github/scenery/js/util/ShaderProgram.js
  50:9  error  Unexpected console statement  no-console
  51:9  error  Unexpected console statement  no-console
  52:9  error  Unexpected console statement  no-console
  53:9  error  Unexpected console statement  no-console
  54:9  error  Unexpected console statement  no-console
  55:9  error  Unexpected console statement  no-console

/Users/samreid/github/scenery/js/util/Util.js
  286:13  error  Unexpected console statement  no-console
  287:13  error  Unexpected console statement  no-console
  288:13  error  Unexpected console statement  no-console
  309:13  error  Unexpected console statement  no-console
  330:13  error  Unexpected console statement  no-console
  351:13  error  Unexpected console statement  no-console
  363:9   error  Unexpected console statement  no-console
  364:9   error  Unexpected console statement  no-console
  408:9   error  Unexpected console statement  no-console
  409:9   error  Unexpected console statement  no-console
  410:9   error  Unexpected console statement  no-console

/Users/samreid/github/scenery-phet/js/demo/ButtonsView.js
  33:30  error  Unexpected console statement  no-console
  47:30  error  Unexpected console statement  no-console

/Users/samreid/github/scenery-phet/js/demo/ComponentsView.js
  139:7  error  Unexpected console statement  no-console

/Users/samreid/github/scenery-phet/js/demo/SpringControls.js
  27:21  error  Strings must use singlequote  quotes

/Users/samreid/github/sun/js/Carousel.js
  98:45  error  Unexpected trailing comma  comma-dangle

/Users/samreid/github/sun/js/FontAwesomeNode.js
  18:17  error  Strings must use singlequote  quotes
  19:14  error  Strings must use singlequote  quotes
  20:11  error  Strings must use singlequote  quotes
  21:17  error  Strings must use singlequote  quotes
  22:16  error  Strings must use singlequote  quotes
  23:12  error  Strings must use singlequote  quotes
  24:18  error  Strings must use singlequote  quotes
  25:11  error  Strings must use singlequote  quotes
  26:10  error  Strings must use singlequote  quotes
  27:12  error  Strings must use singlequote  quotes
  28:17  error  Strings must use singlequote  quotes
  29:19  error  Strings must use singlequote  quotes
  30:15  error  Strings must use singlequote  quotes
  31:16  error  Strings must use singlequote  quotes
  32:19  error  Strings must use singlequote  quotes
  45:13  error  Strings must use singlequote  quotes

✖ 172 problems (172 errors, 0 warnings)

@samreid
Copy link
Member Author

samreid commented Oct 2, 2015

I don't want to spend much time on this without getting a +1 from other devs, but I do want to commit my changes so that we can easily continue if we decide to.

samreid added a commit to phetsims/bending-light that referenced this issue Oct 2, 2015
samreid added a commit that referenced this issue Oct 2, 2015
@samreid
Copy link
Member Author

samreid commented Oct 2, 2015

I posted this in the google group:

https://groups.google.com/forum/#!forum/developing-interactive-simulations-in-html5

I'm investigating ESLint support in chipper as part of #235 . The package.json got 2 new dependencies, so developers and build processes will likely have to run npm install from chipper before the next build.

Please report any issues here, and have a nice weekend!
Sam

@samreid
Copy link
Member Author

samreid commented Oct 2, 2015

To get my eslint rule sealegs, I'm writing a rule that checks that each file has a copyright statement. Here are some typos/errors I'm seeing (and fixing):

// Copyright 2002-2014, University of Colorado Boulder Boulder
// Copyright 2002-2014, University of Colorado
/*
 * Copyright 2002-2014, University of Colorado Boulder
 */

etc.

samreid added a commit that referenced this issue Oct 2, 2015
samreid added a commit to phetsims/scenery that referenced this issue Oct 2, 2015
samreid added a commit to phetsims/bending-light that referenced this issue Oct 2, 2015
samreid added a commit to phetsims/phet-core that referenced this issue Oct 2, 2015
samreid added a commit to phetsims/scenery-phet that referenced this issue Oct 2, 2015
samreid added a commit to phetsims/dot that referenced this issue Oct 2, 2015
@samreid
Copy link
Member Author

samreid commented Oct 2, 2015

Writing my own rule and applying it was a very positive experience. However, I'm unable to get IDEA to use my dynamic rules in its checking. It shows this error:
image

@samreid
Copy link
Member Author

samreid commented Oct 2, 2015

Moving from "additional rules directory" to the options seems to have fixed this:
--rulesdir /Users/samreid/github/chipper/eslint/rules

@pixelzoom
Copy link
Contributor

Looks like some common-code repos do have "grunt-eslint": "~17.2.0" (e.g. axon) while others don't (e.g. scenery-phet, sun).

@samreid
Copy link
Member Author

samreid commented Oct 6, 2015

After the above commits grunt-all.sh eslint is now passing.

@pixelzoom
Copy link
Contributor

% cd sun
% grunt eslint
Warning: Task "eslint" not found. Use --force to continue.

Aborted due to warnings.
%

samreid added a commit to phetsims/seasons that referenced this issue Oct 6, 2015
samreid added a commit to phetsims/trig-tour that referenced this issue Oct 6, 2015
samreid added a commit to phetsims/shred that referenced this issue Oct 6, 2015
@pixelzoom
Copy link
Contributor

I had apparently picked up a transient version of chipper that had "auto-fix changes" turned on for ESLint, and it had changed a bunch of files, so my pull-all.sh was failing. Revert changes, pulled latest chipper, and everything looks good.

samreid added a commit to phetsims/perennial that referenced this issue Oct 6, 2015
samreid added a commit to phetsims/mobius that referenced this issue Oct 6, 2015
samreid added a commit to phetsims/rosetta that referenced this issue Oct 6, 2015
@samreid
Copy link
Member Author

samreid commented Oct 6, 2015

I changed grunt-all to use active-repos instead of active-runnables and went through a build to make sure all appropriate repos have eslint, and are linting properly. Optics lab is still an exception (as it was for jshint), but unless I have made a manual error, everything else is good to go.

Next steps:

  1. Integrate eslint into the main build process
  2. Get rid of jshint
  3. add .gitignore for the .eslint cache files
  4. check through to see if there are other prebuilt rules we want/need
  5. add documentation to the eslint files in chipper

This "Investigate ESList" thread is getting a bit long and indeed our "investigation" is over, so I'll move the remaining work to a new issue and close this one.

@samreid samreid mentioned this issue Oct 6, 2015
6 tasks
@samreid
Copy link
Member Author

samreid commented Oct 6, 2015

New issue created above, I'll close this one.

@samreid
Copy link
Member Author

samreid commented Oct 8, 2015

One more answer to this question:

Question about ESLint caching... If the options to ESLint are changed, is it smart enough to invalidate the caches?

It appears if you change the .js code of a rule definition, it does *not invalidate caches.

@pixelzoom
Copy link
Contributor

We could add support for deleting caches to the build process. But you can delete all caches like this:

% cd /Users/cmalley/PhET/GitHub
% rm */.eslintcache

@samreid
Copy link
Member Author

samreid commented Oct 8, 2015

I also added a grunt command line argument --disable-eslint-cache which you can be used for iterating on rules.

@pixelzoom
Copy link
Contributor

Does --disable-eslint-cache delete caches? Or just turn off caching? If the latter, that doesn't solve the problem. If a rule's code is changed, the caches need to be deleted.

@samreid
Copy link
Member Author

samreid commented Oct 8, 2015

Does --disable-eslint-cache delete caches?

It just disables it for the current run, the cache is not deleted.

@AshrafSharf
Copy link

@samreid please let me know what is the resolution on this? I am using windows machine.
Would setting the idea config or git global config solve the problem?

@samreid
Copy link
Member Author

samreid commented Oct 8, 2015

@AshrafSharf we have removed the line ending rule from the linting rules and will be discussing the issue shortly in #380

samreid added a commit to phetsims/molecules-and-light that referenced this issue Oct 27, 2015
samreid added a commit to phetsims/molecules-and-light that referenced this issue Oct 27, 2015
jessegreenberg pushed a commit to phetsims/greenhouse-effect that referenced this issue Apr 21, 2021
jessegreenberg pushed a commit to phetsims/greenhouse-effect that referenced this issue Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants