JavaScript style checkers

169 views
Skip to first unread message

Jörn Zaefferer

unread,
Oct 8, 2013, 5:59:52 AM10/8/13
to js-t...@googlegroups.com
I've been looking for tools that can check the style of JavaScript programs, format the code or both. I found a few and wanted to share those, along with checking which ones I'm missing.

You probably know about jsbeautifier. That's an oldie, but lacks in configuration options - it's very limited in the style of code is outputs: https://github.com/einars/js-beautify#options

A tool that only checks for issues, without trying to format the code, JSCS, aka JavaScript Code Style: https://github.com/mdevils/node-jscs
As most tools these days, it comes with a grunt wrapper: https://github.com/gustavohenke/grunt-jscs-checker
jQuery Core is adopting this: https://github.com/jquery/jquery/pull/1396

This takes an annotated AST, via Rocambole, to format the code, including comments. This can be pretty complex and brittle at times, but provides the most complete solution to formatting in any style.
By default it follows the Google JS Style Guide. I've been working on implementing a preset for the jQuery Style Guide (http://contribute.jquery.org/style-guide/js/), which still isn't quite there yet: https://github.com/millermedeiros/esformatter/pull/46

What other tools are there? Which ones are you using? Any interesting in helping out with jscs or esformatter? Both projects could use help from JS tool developers.

Regards
Jörn

Peter van der Zee

unread,
Oct 8, 2013, 7:28:12 AM10/8/13
to Unname
There's Syntux: https://github.com/ehd/syntux , but it's also a bit old and abandoned.


--
--
http://clausreinke.github.com/js-tools/resources.html - tool information
http://groups.google.com/group/js-tools - mailing list information
 
---
You received this message because you are subscribed to the Google Groups "js-tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to js-tools+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

austincheney

unread,
Oct 16, 2013, 3:20:06 PM10/16/13
to js-t...@googlegroups.com
Jorn,

I wrote one I call JSPretty.

You can demo it at:
http://prettydiff.com/?m=beautify&l=javascript&c=white

It features an auto-correction feature to make the output more JSLint friendly that you can demo at:
http://prettydiff.com/?m=beautify&l=javascript&c=white&jscorrect

It can also provide scope analysis that you can demo at:
http://prettydiff.com/?m=beautify&l=javascript&c=white&jsscope
http://prettydiff.com/?m=beautify&l=javascript&c=white&jscorrect&jsscope

The source code is available at:
http://prettydiff.com/lib/jspretty.js
https://github.com/austincheney/Pretty-Diff/blob/master/lib/jspretty.js

I recognize that my code uses short variable names, which is a source of absolute emotional failure for some developers.  Any other comments or criticism are wonderfully appreciated.

Austin
Reply all
Reply to author
Forward
0 new messages