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

fix: emit warning/error if no config was found/given #286

Merged
merged 4 commits into from Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions index.js
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
@@ -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();
}
);
}
);