We decided to configure JSLint on a per-file basis. This way, every file can have its own options which allows us a bit of flexibility. If you want to allow the use of the increment and decrement operators in a file, and you want common browser properties like
document to appear predefined (JSLint will throw
undefined errors if they don’t), you can do so with a
jslint directive at the top of the code:
There are some JSLint options that allow you to get away with sloppy code formatting (such as the
white option, which will allow “messy white space”). Unfortunately, there is no way to enforce that this option is always turned on, so we have to simply make developers aware that such options must not be set in any files. If they were, it would kind of defeat the point.
Enforcing the use of JSLint
There’s a couple of things that are required for our hook to work. The first is Node.js (along with NPM, the Node Package Manager). Once you’ve got those up and running, you can globally install node-jslint which will add the executable to your path:
Keeping track of our hook
One of the problems with Git hooks is that they are not part of the repository itself (since they live within the
.git directory). We don’t expect to be changing our hook regularly, but it would be nice to have the hook itself under version control. We achieved this by simply finding a suitable location in the repository, and creating the hook script there. When anyone sets up their development environment, a single command can be run to activate the hook, by symlinking to the hook file from the Git hooks directory:
In the near future we would like to get this step integrated into a more general “development environment setup” script, so that new starters or anyone setting up a clean dev environment can kick off one script and come back later to a fully working local copy of the app.