Daniel Irvine on building software
Running JSLint across multiple files
7 August 2014
There’s no denying it: JSLint is a great tool. But it lacks the ability to test multiple files within one runtime context without producing undefined symbol errors.
JSLint can test multiple files at once, using a command line like this:
$ find . -name **/*.js -print0 | xargs -0 jslint
#14 'NoughtsAndCrosses' was used before it was defined. NoughtsAndCrosses.Game.start(?args); // Line 95, Pos 5
One way this issue occurs is when linting both an implementation file and its corresponding spec file:
game.js // Game implementation game_spec.js // Jasmine tests for game.js
Crucially, the Jasmine tests run via a third file,
game_spec.js refer to functions within
TestRunner.html ensures both
game.js and then
game_spec.js are loaded in the same runtime context.
The only workaround I’ve found so far is to add a global directive at the top of files which reference other constants. In
game_spec.js I have the following line.
/*global Game: true*/