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

Commit 4204560

Browse files
ricardogobbosouzaevilebottnawi
authored andcommitted
fix: emit warning/error if no config was found/given (#286)
1 parent 997cce5 commit 4204560

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

index.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ module.exports = function(input, map) {
235235

236236
webpack.cacheable();
237237

238+
var emitter = config.emitError ? webpack.emitError : webpack.emitWarning;
238239
var engine = engines[configHash];
239240
var resourcePath = webpack.resourcePath;
240241
var cwd = process.cwd();
@@ -255,7 +256,7 @@ module.exports = function(input, map) {
255256
options: config,
256257
source: input,
257258
transform: function() {
258-
return lint(engine, input, resourcePath);
259+
return lint(engine, input, resourcePath, emitter);
259260
}
260261
},
261262
function(err, res) {
@@ -276,10 +277,20 @@ module.exports = function(input, map) {
276277
}
277278
);
278279
}
279-
printLinterOutput(lint(engine, input, resourcePath), config, webpack);
280+
printLinterOutput(
281+
lint(engine, input, resourcePath, emitter),
282+
config,
283+
webpack
284+
);
280285
webpack.callback(null, input, map);
281286
};
282287

283-
function lint(engine, input, resourcePath) {
284-
return engine.executeOnText(input, resourcePath, true);
288+
function lint(engine, input, resourcePath, emitter) {
289+
try {
290+
return engine.executeOnText(input, resourcePath, true);
291+
} catch (_) {
292+
if (emitter) emitter(_);
293+
294+
return { src: input };
295+
}
285296
}

test/no-eslint-configuration.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var test = require("ava");
2+
var webpack = require("webpack");
3+
4+
var conf = require("./utils/conf");
5+
6+
test.cb(
7+
"eslint-loader emit warning when there is no eslint configuration",
8+
function(t) {
9+
t.plan(2);
10+
webpack(
11+
conf(
12+
{
13+
entry: "./test/fixtures/good.js"
14+
},
15+
{
16+
cwd: "/"
17+
}
18+
),
19+
function(err, stats) {
20+
if (err) {
21+
throw err;
22+
}
23+
24+
t.true(stats.hasWarnings());
25+
t.regex(
26+
stats.compilation.warnings[0].message,
27+
/no eslint configuration/i
28+
);
29+
t.end();
30+
}
31+
);
32+
}
33+
);

0 commit comments

Comments
 (0)