编辑:由于我发布了这个答案,我已经清理并显着扩展了我在下面写的代码,并将它作为自己的包发布在npm:jshint-stylish-summary
上。
下面是一个输出的截图:
jshint-stylish
似乎不支持最后的总结。你可能想要寻找一个不同的记者,做你想做的事。如果你想使用jshint-stylish
保持(快速perusal of mine没有屈服但是任何有用的东西。)
,你还必须添加a custom reporter的选项。这里有一个我实施了应该让你开始:
var map = require('map-stream');
var jshintTotalReporter = function() {
var total = { warnings: 0, errors: 0 };
total.files = { all: 0, success: 0, warning: 0, error: 0 };
return {
collect: map(function(file, cb) {
var codes = { W: 0, E: 0 };
(file.jshint.results||[]).forEach(function(result) {
codes[result.error.code[0]]++;
});
total.warnings += codes['W'];
total.errors += codes['E'];
total.files.all++;
total.files.success += (codes['W'] + codes['E'] > 0) ? 0 : 1;
total.files.warning += (codes['W'] > 0) ? 1 : 0;
total.files.error += (codes['E'] > 0) ? 1 : 0;
cb();
}),
report: function() {
console.log(total.files.all + ' files checked');
console.log(total.files.success + ' files without problems');
console.log(total.files.warning + ' files with warnings (' +
total.warnings + ' warnings total)');
console.log(total.files.error + ' files with errors (' +
total.errors + ' errors total)');
}
};
};
gulp.task('lint', function() {
var jshintTotals = jshintTotalReporter();
return gulp.src(paths.scripts)
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshintTotals.collect)
.on('end', jshintTotals.report);
});
(不要忘了运行npm install --save-dev map-stream
或这将无法工作)。
输出相当简陋,但应该包含所有可能感兴趣的信息。例如:
9 files checked
3 files without problems
6 files with warnings (13 warnings total)
4 files with errors (7 errors total)
如果要漂亮的东西,你可以使用chalk
一些颜色添加到输出和log-symbols
为jshint-stylish
用途可爱的小图标。