JavaScript style checker with JSCS

JavaScript style checker with JSCS

Julen Pardo གིས-
Number of replies: 7

Hi all,

I've been looking for a tool for checking JavaScript style acording to the defined guidelines, but unfortunately, I've not found nothing defined.

After trying some tools (PHP CodeSniffer, ESLint) that resulted to be quite hard/labourious, I've found an easy configurable tool that allows to define the rules defined by Moodle, in an easy way. That tools is JSCS (JavaScript Code Style).

I've defined some rules (not all, but the most significant ones), which are available in this GitHub repository: https://github.com/julenpardo/moodle-javascript_style_checker.

I hope it can be useful for those developing JavaScript plugins for Moodle.


Best regards,

Julen

དཔྱ་སྙོམས་ཀྱི་སྐུགས་ཚུ།:Useful (1)
In reply to Julen Pardo

Re: JavaScript style checker with JSCS

David Scotson གིས-

I'm interested in this, I filed a bug about it a short while ago:

https://tracker.moodle.org/browse/MDL-52127


My suggested starter was this, we should compare notes:

https://gist.github.com/davidscotson/9d68b98663266152e774

In reply to David Scotson

Re: JavaScript style checker with JSCS

Dan Poltawski གིས-

Have you guys seen our .jshintrc? I thought there was a note about jshint in our coding style but seems not. Note that modules (amd or yui) built with grunt will be linted with jshint (though unfortunately the one which YUI uses is slightly older).

I have not looked at the javascript coding style checker but if it provides useful value over jshint - I think its possible we could incorporate that into our js build process (assuming there would be possible ways to silence the checker when there really isn't a solution to a particular style check).

Edit: Doh, just seen Damyons response.

In reply to David Scotson

Re: JavaScript style checker with JSCS

Julen Pardo གིས-

Hi David,

I didn't realise there was an open bug in the tracker about this topic.

I will look at your snippet in depth throughout this week, but at first sight I see some rules I didn't realise that were configurable (especially the jsDoc documentation part).


Best regards,

Julen

In reply to Julen Pardo

Re: JavaScript style checker with JSCS

Damyon Wiese གིས-
How is this different from jshint (which we already call from grunt/shifter when minifying JS)?
In reply to Damyon Wiese

Re: JavaScript style checker with JSCS

Julen Pardo གིས-

Hi Damyon,

I discovered this tool reading JSHint documentation, which suggests to use JSCS "if you would like to enforce rules relating to code style" (e.g. to enforce camelcase notation) དགའ་འཛུམ་


Best regards,

Julen

In reply to Damyon Wiese

Re: JavaScript style checker with JSCS

David Scotson གིས-

jscs is more about where spaces and brackets go and enforcing formatting.


jshint is more a static analysis tools that might reveal when you're doing something you shouldn't in your code (using the wrong kind of comparison).


There is a little bit of overlap, but there's functionality in jshint that overlapped that they removed and explicitly point you towards jscs in their documentation.


camelcase Warning This option has been deprecated and will be removed in the next major release of JSHint.

JSHint is limiting its scope to issues of code correctness. If you would like to enforce rules relating to code style, check out the JSCS project.


edit: heh, should really read the whole thread before I reply, just repeating what's already been said.

In reply to David Scotson

Re: JavaScript style checker with JSCS

Damyon Wiese གིས-
Thanks for explaining what the different tools are meant for - it sounds like it would be great to integrate jscs with the grunt task.