Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// custom jshint-loader reporter
// Based on https://github.com/sindresorhus/jshint-stylish
var
beeper = require('beeper'),
chalk = require('chalk'),
table = require('text-table'),
stringLength = require('string-length'),
logSymbols = require('log-symbols');
function pluralize(str, count) {
return str + (count === 1 ? '' : 's');
}
module.exports = function(errors) {
var message = '';
var total = errors.length;
var errorCount = 0;
var warningCount = 0;
message += table(errors.map(function (err, i) {
// TODO: why does this occur?
if(!err)
return '';
// E: Error, W: Warning, I: Info
var isError = err && err.code && err.code[0] === 'E';
var line = [
'',
chalk.gray('line ' + err.line),
chalk.gray('col ' + err.character),
isError ? chalk.red(err.reason) : (process.platform !== 'win32' ? chalk.blue(err.reason) : chalk.cyan(err.reason)),
chalk.gray('(' + err.code + ')'),
'\n',
' ',
chalk.white.bold(err.evidence)
];
if (isError) {
errorCount++;
} else {
warningCount++;
}
return line;
}), {
stringLength: stringLength
})
+ '\n\n';
if (total > 0) {
if (errorCount > 0) {
message += ' ' + logSymbols.error + ' ' + errorCount + pluralize(' error', errorCount) + (warningCount > 0 ? '\n' : '');
}
message += ' ' + logSymbols.warning + ' ' + warningCount + pluralize(' warning', total);
} else {
message += ' ' + logSymbols.success + ' No problems';
message = '\n' + ret.trim();
}
message = "\n" + chalk.red('jshint report:') + "\n"
+ message;
var emitter = this.emitWarning;
if(!emitter)
throw new Error("Your module system doesn't support emitWarning. Update availible? \n" + message);
beeper();
emitter(message);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment