Permalink
Browse files

jslint is now called on each JavaScript file

  • Loading branch information...
1 parent d59191a commit 487d2e45482f1e3a6645b203243eb480ad8bff97 @davybrion committed Aug 14, 2011
Showing with 30 additions and 9 deletions.
  1. +1 −1 bin/jslint-all.js
  2. +29 −8 lib/runner.js
View
@@ -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) {
-
+
});
View
@@ -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) {
@@ -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.