grunt jshint2
The task I want the grunt-contrib-jshint task to be.
Why another one?
I offered to merge but they didn't seem interested in saving puppies.
Options
Here is an example config showing the default options.
var cfg = jshint2: options: // A path to your jshintrc file if you'd like to use one jshintrc: undefined // jshint options to be passed to jshint.lint. jshint: // A list of predefined variables passed to jshint.lint globals: // What reporter you'd like to use; see Reporters for more info reporter: "default" // Do not fail task on jshint errors force: false // Cache successful files; see Caching for more info cache: true // Use the 'async' or 'cluster' processor; see Processors for more info processor: "async" // When using the async processor, the max number of files to process at a time. spawnLimit: 5 ;
Caching
Caching is done by keeping a computed sha1 hash of the file contents, the jshint options (stringified) and the globals passed to the jshint.lint function.
{ var sha1 = crypto; // The hash should include the file contents sha1; // And the jsHintOpts sha1; // And the globals sha1; return sha1;}
After a file is successfully linted an empty file with a name matching it's computed
hash is created in a temp directory (using os.tmpDir()
). On subsequent jshint calls
an existence check of the file determines whether we can skip validating it a second time.
By default, the directory where cached files is stored is dependant on the module version. So updating the module will invalidate any already cached files.
Reporters
Reporters offer a way to customize the output of the jshint2 task. Since jshint's reporters seem to be in a state of flux at the moment, I've copied their implementations over in order to maintain continuity.
A reporter can be specified in three ways
- string (ie. "default" or "xml")
- class (ie.
require("grunt-jshint2").reporters.xml
) - object with the following interface:
// Reporters interfacevar myReporter = { // The task is starting to process files } { // A file was successfully linted } { // A file had errors } { // The task is finished processing };
Custom objects will have their options
attribute set to the task options. More information available from the lib/reporterResolver.js
file.
Processors
A processor takes a list of files, some jshint options and globals and runs jshint on each file. The default processor is an asynchronous processor that reads each file and runs jshint. Other processors like the cluster processor can take advantage of multi core machines in order to run jshint on different threads.
At this time it's not possible to write your own processor, but here is the interface that each processor should implement.
{ // Options contains; files, jsHintOpts, globals, cache, spawnLimit thisoptions = options;} _; _;
License
Copyright 2013, 2014 Jacob Gable, MIT License.