Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
fix: emit warning/error if no config was found/given (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza authored and evilebottnawi committed Jul 10, 2019
1 parent 997cce5 commit 4204560
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
19 changes: 15 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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 };
}
}
33 changes: 33 additions & 0 deletions test/no-eslint-configuration.js
Original file line number Diff line number Diff line change
@@ -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();
}
);
}
);

0 comments on commit 4204560

Please sign in to comment.