Skip to content

Commit

Permalink
jslint is now called on each JavaScript file
Browse files Browse the repository at this point in the history
  • Loading branch information
davybrion committed Aug 14, 2011
1 parent d59191a commit 487d2e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bin/jslint-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ if (!options.argv.remain.length) {
var pathToCheck = path.resolve(path.normalize(options.argv.remain[0]));
delete options.argv;
runner.check(pathToCheck, options, function(err, results) {

});
37 changes: 29 additions & 8 deletions lib/runner.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var fs = require('fs'),
path = require('path'),
exec = require('child_process').exec;

// TODO: rewrite this to make it fully asynchronous
var exec = require('child_process').exec
fs = require('fs'),
jslint = require('./jslint.js'),
fileCount = 0,
results = [];

function getJsFilesRecursively(startPath, callback) {
exec('find ' + startPath, function(err, stdout) {
Expand All @@ -17,14 +17,35 @@ function getJsFilesRecursively(startPath, callback) {
});
};

function lint(filepath, options, postcallback) {
fs.readFile(filepath, function(err, data) {
if (err) { callback(err); }
data = data.toString('utf8').replace(/^\#\!.*/, "");

if (!jslint(data, options)) {
results.push(jslint.data());
};

postcallback();
});
};

module.exports = {
check: function(path, options, callback) {
if (!options.hasOwnProperty('node')) { options.node = true; }
if (!options.hasOwnProperty('es5')) { options.es5 = true; }

var postLint = function() {
if (--fileCount === 0) {
callback(null, results);
};
};

getJsFilesRecursively(path, function(err, jsFiles) {
fileCount = jsFiles.length;
jsFiles.forEach(function(f) {
console.log(f);
lint(f, options, postLint);
});
});

callback(null, null);
}
};

0 comments on commit 487d2e4

Please sign in to comment.