less-terrible-coffeelint-loader
Advanced tools
Comparing version 0.1.2 to 0.1.3
29
index.js
@@ -24,3 +24,3 @@ 'use strict'; | ||
var rcFinder = new RcFinder('.coffeelint.json', { | ||
var rcFinder1 = new RcFinder('.coffeelint.json', { | ||
loader: function (rcpath) { | ||
@@ -31,5 +31,15 @@ return rcpath; | ||
var rcFinder2 = new RcFinder('coffeelint.json', { | ||
loader: function (rcpath) { | ||
return rcpath; | ||
} | ||
}); | ||
var loadConfigSync = function () { | ||
var folder = path.dirname(this.resourcePath); | ||
var rcpath = rcFinder.find(folder); | ||
var rcFinders = [rcFinder1, rcFinder2]; | ||
var rcpath; | ||
while (rcFinders.length && typeof rcpath !== 'string') { | ||
rcpath = rcFinders.shift().find(folder); | ||
} | ||
if (typeof rcpath !== 'string') { | ||
@@ -47,5 +57,9 @@ // No .coffeelint.json found. | ||
var folder = path.dirname(this.resourcePath); | ||
rcFinder.find(folder, function (err, rcpath) { | ||
var rcFinders = [rcFinder1, rcFinder2]; | ||
var rcFinderCallback = function (err, rcpath) { | ||
if (typeof rcpath !== 'string') { | ||
// No .coffeelint.json found. | ||
if (rcFinders.length) { | ||
return rcFinders.shift().find(folder, rcFinderCallback); | ||
} | ||
return callback(null, {}); | ||
@@ -68,3 +82,4 @@ } | ||
}); | ||
}.bind(this)); | ||
}.bind(this); | ||
rcFinders.shift().find(folder, rcFinderCallback); | ||
}; | ||
@@ -83,4 +98,2 @@ | ||
// Move flags. | ||
var emitErrors = config.emitErrors; | ||
delete config.emitErrors; | ||
var failOnHint = config.failOnHint; | ||
@@ -95,3 +108,3 @@ delete config.failOnHint; | ||
if (errors.length > 0) { | ||
reporter.call(this, errors, emitErrors); | ||
reporter.call(this, errors); | ||
@@ -131,2 +144,2 @@ if (failOnHint && errors.length > 0) { | ||
}.bind(this)); | ||
}; | ||
}; |
@@ -5,6 +5,6 @@ 'use strict'; | ||
module.exports = function(errors, emitErrors) { | ||
var emitter = emitErrors ? this.emitError : this.emitWarning; | ||
module.exports = function(errors) { | ||
var errorCount = errors.filter(function(error) { return (error.level === 'error'); }).length; | ||
var warningCount = errors.filter(function(error) { return (error.level === 'warning'); }).length; | ||
var warningCount = errors.filter(function(error) { return (error.level === 'warn'); }).length; | ||
var emitter = errorCount ? this.emitError : this.emitWarning; | ||
@@ -14,9 +14,10 @@ var report = table(errors.map(function(error) { | ||
'', | ||
chalk.gray(error.lineNumber), | ||
chalk.yellow(error.level), | ||
error.message | ||
chalk.reset.grey(error.lineNumber), | ||
error.level === 'error' ? chalk.red('error') : chalk.yellow('warning'), | ||
error.message, | ||
chalk.dim(error.name || "") | ||
]; | ||
if (error.context) { | ||
line.push(chalk.grey(error.context)); | ||
line.push(chalk.grey('\'' + error.context + '\'')); | ||
} | ||
@@ -28,5 +29,8 @@ | ||
if (errors.length > 0) { | ||
report = report + | ||
report = '\n' + | ||
chalk.underline[errorCount ? "red" : "yellow"](this.resourcePath) + | ||
'\n' + | ||
report + | ||
'\n\n' + | ||
chalk.yellow([ | ||
chalk.bold[errorCount ? "red" : "yellow"]([ | ||
'✖ ', | ||
@@ -37,10 +41,13 @@ errors.length, | ||
errorCount, | ||
' errors, ', | ||
' error' + | ||
(errorCount !== 1 ? 's' : '') + | ||
', ', | ||
warningCount, | ||
' warnings)' | ||
' warning' + | ||
(warningCount !== 1 ? 's' : '') + | ||
')\n' | ||
].join('')); | ||
} | ||
emitter(report); | ||
}; | ||
emitter(new Error(report)); | ||
}; |
{ | ||
"name": "less-terrible-coffeelint-loader", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"author": "Tommy Brunn <tommy.brunn@gmail.com", | ||
@@ -5,0 +5,0 @@ "description": "Coffeelint loader module for webpack", |
@@ -29,6 +29,2 @@ # Less Terrible Coffeelint Loader | ||
// coffeelint errors are displayed by default as warnings | ||
// set emitErrors to true to display them as errors | ||
emitErrors: false, | ||
// coffeelint to not interrupt the compilation | ||
@@ -35,0 +31,0 @@ // if you want any file with coffeelint errors to fail |
9674
157
86