Created
January 24, 2015 10:45
-
-
Save dashed/ed941052b82fd7694320 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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