Jenkins: Use node-jscs as checkstyle for javascript coding style
Closed, ResolvedPublic

Description

See https://github.com/mdevils/node-jscs

This is the first tool I've seen in the category of asserting coding style for javascript that actually looks like it is worth looking into further.

I intend to experiment with it in the near future for 1 or 2 projects, first in non-voting mode and perhaps later to become a standard enabled job for many projects.


Version: wmf-deployment
Severity: enhancement

Details

Reference
bz54218
bzimport raised the priority of this task from to Normal.
bzimport set Reference to bz54218.
Krinkle created this task.Sep 17 2013, 11:01 AM

Is that a replacement for JSHint or unrelated?

node-jscs would be purely for coding style, not code quality (which is what jshint is primarily for).

Although there are a few minor things that jshint does in the realm of coding style, those are arguably code quality as well (like using of braces in if/else blocks).

This would allow us to validate the complete coding style (especially with regards to whitespace), which right now is mostly enforced by leaving comments in code review and fixup commits pointing to [[mw:CC/JS]].

Change 99596 had a related patch set uploaded by Krinkle:
Set up node-jscs, pass it, and configure in local Gruntfile

https://gerrit.wikimedia.org/r/99596

Change 99596 merged by jenkins-bot:
Set up node-jscs, pass it, and configure in local Gruntfile

https://gerrit.wikimedia.org/r/99596

Now merged locally in the repo for VisualEditor, and appears to be adding value; moving back to NEW for consideration to be added to jenkins for automated running.

Change 100732 had a related patch set uploaded by Krinkle:
Set up node-jscs, pass it, and configure in local Gruntfile

https://gerrit.wikimedia.org/r/100732

Change 100732 merged by jenkins-bot:
Set up node-jscs, pass it, and configure in local Gruntfile

https://gerrit.wikimedia.org/r/100732

Change 111963 had a related patch set uploaded by Krinkle:
[WIP] Set up node-jscs via Grunt (and pass it)

https://gerrit.wikimedia.org/r/111963

Change 111963 merged by jenkins-bot:
Set up node-jscs via Grunt (and pass it)

https://gerrit.wikimedia.org/r/111963

Is this intended to be a tracking bug for every repo, a bug for it to be done automatically for all repos and then repos that now break need to fix themselves, or can it be marked as FIXED?

The bug is to figure out how to properly do it. Which I define by hacking it together for one repo, and as you repeat it for more repos you refine it until it seems sensible/maintainable.

I think we've reached that point. Any further repos that want it, can enable it the same way other pipelines are introduced. By patching their Gruntfile or adding a new npm-test pipeline.

Sounds good to me Timo. That nicely scale up CI to developers :-)

Is there work being done to get this run on ci? I'd like to push this for Wikibase as well :)

Is there work being done to get this run on ci? I'd like to push this for Wikibase as well :)

You will need a package.json and a npm 'test' entry point with a devDependencies for grunt-jscs. From there we can add a Jenkins job that invokes 'npm test' and that should run jscs.

Example:

https://gerrit.wikimedia.org/r/#/c/100732/

More details at https://www.mediawiki.org/wiki/Continuous_integration/Test_entry_points#JavaScript :-)

Cool, thanks. I added npm test, although I didn't go through grunt since we are not running any other grunt jobs, yet:

demon removed a subscriber: demon.Jan 13 2015, 1:19 PM

Cool, thanks. I added npm test, although I didn't go through grunt since we are not running any other grunt jobs, yet:

That's quite alright. If you don't need do run bash commands like mv, cp, rm, ln etc. which might not work cross-platform if put inside scripts.test (so you'll want to use a nodejs script or Grunt task for that); Running programs like jscs and jshint directly is perfectly fine and actually quite common. I've recently started to use this more often as well. Only use Grunt when there's a need for it. This avoids added complexity, needless abstraction, and indirect dependencies on the underlying framework (e.g. jscs/jshint) which can be quite annoying since it doesn't like being pinned to a direct version that way.

http://blog.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/
http://ponyfoo.com/articles/choose-grunt-gulp-or-npm