Skip to content

Commit

Permalink
fix: hooks and callback error
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Dec 20, 2019
1 parent b7f3679 commit 3e7c36e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function linter(options, compiler, callback) {

let { errors, warnings } = parseResults(options, results);

compiler.hooks.afterCompile.tapAsync(
compiler.hooks.afterEmit.tapAsync(
'ESLintWebpackPlugin',
(compilation, next) => {
if (warnings.length > 0) {
Expand Down Expand Up @@ -85,7 +85,15 @@ export default function linter(options, compiler, callback) {
callback();
}
} catch (e) {
callback(e);
compiler.hooks.afterEmit.tapAsync(
'ESLintWebpackPlugin',
(compilation, next) => {
compilation.errors.push(new ESLintError(e.message));
next();
}
);

callback();
}
}

Expand Down
9 changes: 7 additions & 2 deletions test/empty.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ describe('empty', () => {
const compiler = webpack({
context: join(__dirname, 'fixtures', 'empty'),
mode: 'development',
entry: '../index',
plugins: [new ESLintPlugin()],
});

compiler.run((err) => {
expect(err.message).toMatch(/No files matching/i);
compiler.run((err, stats) => {
const { errors } = stats.compilation;
expect(stats.hasWarnings()).toBe(false);
expect(stats.hasErrors()).toBe(true);
expect(errors).toHaveLength(1);
expect(errors[0].message).toMatch(/No files matching/i);
done();
});
});
Expand Down
8 changes: 6 additions & 2 deletions test/fail-on-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ describe('fail on config', () => {
const configFile = join(__dirname, '.badeslintrc');
const compiler = pack('error', { configFile });

compiler.run((err) => {
expect(err.message).toMatch(
compiler.run((err, stats) => {
const { errors } = stats.compilation;
expect(stats.hasWarnings()).toBe(false);
expect(stats.hasErrors()).toBe(true);
expect(errors).toHaveLength(1);
expect(errors[0].message).toMatch(
/ESLint configuration in --config is invalid/i
);
done();
Expand Down

0 comments on commit 3e7c36e

Please sign in to comment.