diff --git a/index.js b/index.js index 73cc587..38fa855 100644 --- a/index.js +++ b/index.js @@ -235,6 +235,7 @@ module.exports = function(input, map) { webpack.cacheable(); + var emitter = config.emitError ? webpack.emitError : webpack.emitWarning; var engine = engines[configHash]; var resourcePath = webpack.resourcePath; var cwd = process.cwd(); @@ -255,7 +256,7 @@ module.exports = function(input, map) { options: config, source: input, transform: function() { - return lint(engine, input, resourcePath); + return lint(engine, input, resourcePath, emitter); } }, function(err, res) { @@ -276,10 +277,20 @@ module.exports = function(input, map) { } ); } - printLinterOutput(lint(engine, input, resourcePath), config, webpack); + printLinterOutput( + lint(engine, input, resourcePath, emitter), + config, + webpack + ); webpack.callback(null, input, map); }; -function lint(engine, input, resourcePath) { - return engine.executeOnText(input, resourcePath, true); +function lint(engine, input, resourcePath, emitter) { + try { + return engine.executeOnText(input, resourcePath, true); + } catch (_) { + if (emitter) emitter(_); + + return { src: input }; + } } diff --git a/test/no-eslint-configuration.js b/test/no-eslint-configuration.js new file mode 100644 index 0000000..1969738 --- /dev/null +++ b/test/no-eslint-configuration.js @@ -0,0 +1,33 @@ +var test = require("ava"); +var webpack = require("webpack"); + +var conf = require("./utils/conf"); + +test.cb( + "eslint-loader emit warning when there is no eslint configuration", + function(t) { + t.plan(2); + webpack( + conf( + { + entry: "./test/fixtures/good.js" + }, + { + cwd: "/" + } + ), + function(err, stats) { + if (err) { + throw err; + } + + t.true(stats.hasWarnings()); + t.regex( + stats.compilation.warnings[0].message, + /no eslint configuration/i + ); + t.end(); + } + ); + } +);