Skip to content

Commit

Permalink
Format the output
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Oct 25, 2012
1 parent f8c7004 commit bacd04a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
19 changes: 15 additions & 4 deletions bin/modulelint
Expand Up @@ -3,14 +3,12 @@
/**
* Module dependencies.
*/

var program = require('commander'),
fs = require('fs'),
path = require('path'),
lint = require('../');

// options

program
.version(lint.version)
.option('-i, --input <folder>', 'Where is the project');
Expand All @@ -32,8 +30,21 @@ if (!program.input) {
} else {
// process stdin
var input = path.resolve(program.input);
lint.sniffe(input, function (err, result) {
lint.sniffe(input, function (err, results) {
console.log("项目路径:" + input);
console.log(result);
var total = results.reduce(function (memo, currect) {
return memo + currect.score;
}, 0);
console.log("总得分数为:" + total);
console.log("==============");
results.forEach(function (result) {
console.log("检查项:" + result.name);
console.log("得分:" + result.score);
var info = result.info;
var reasons = (Array.isArray(info) && info.length) ? info: (info ? [info] : []);
reasons.forEach(function (reason, index) {
console.log((index + 1) + ". " + reason);
});
});
});
}
File renamed without changes.
42 changes: 40 additions & 2 deletions lib/modulelint.js
@@ -1,8 +1,46 @@
var folder = require('./items/folder.js');
var fs = require('fs');
var path = require('path');
var EventProxy = require('eventproxy');

exports.loadChecklist = function () {
var checklist = [];
// the acutal commands. read them dynamicaly
var files = fs.readdirSync(path.join(__dirname, 'checklist'));

for(var i = 0, ii = files.length; i < ii; i++) {
if (path.extname(files[i]) === ".js") {
var name = path.basename(files[i], '.js');
var checker = require(path.join(__dirname, 'checklist', files[i]));
checker.name = name;
checklist.push(checker);
}
}
return checklist;
};

/**
* In me the tiger sniffe the rose
*/
exports.sniffe = function (source, callback) {
folder.check(source, callback);
var checklist = exports.loadChecklist();
var proxy = new EventProxy();
var length = checklist.length;

proxy.after('checked', length, function (results) {
callback(null, results);
});
proxy.on('error', function (err) {
proxy.unbind();
callback(err);
});
checklist.forEach(function (checker) {
checker.check(source, function (err, result) {
if (err) {
proxy.fire('error', err);
return;
}
result.name = checker.name;
proxy.fire('checked', result);
});
});
};

0 comments on commit bacd04a

Please sign in to comment.