Skip to content

Commit 4ef97cd

Browse files
fix: fail on error and fail on warning (#275)
* fix: fail on error and fail on warning * chore: update deps * chore: update lockfile
1 parent a653827 commit 4ef97cd

File tree

8 files changed

+965
-1057
lines changed

8 files changed

+965
-1057
lines changed

package-lock.json

Lines changed: 915 additions & 1006 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,34 @@
5757
"schema-utils": "^4.3.0"
5858
},
5959
"devDependencies": {
60-
"@babel/cli": "^7.26.4",
61-
"@babel/core": "^7.26.7",
62-
"@babel/preset-env": "^7.26.7",
63-
"@commitlint/cli": "^19.7.1",
64-
"@commitlint/config-conventional": "^19.7.1",
60+
"@babel/cli": "^7.27.0",
61+
"@babel/core": "^7.26.10",
62+
"@babel/preset-env": "^7.26.9",
63+
"@commitlint/cli": "^19.8.0",
64+
"@commitlint/config-conventional": "^19.8.0",
6565
"@types/fs-extra": "^11.0.4",
6666
"@types/micromatch": "^4.0.9",
67-
"@types/node": "^22.13.1",
67+
"@types/node": "^22.14.0",
6868
"@types/normalize-path": "^3.0.2",
6969
"@types/webpack": "^5.28.5",
7070
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
7171
"babel-jest": "^29.7.0",
7272
"chokidar": "^4.0.3",
7373
"cross-env": "^7.0.3",
74-
"cspell": "^8.17.3",
74+
"cspell": "^8.18.1",
7575
"del": "^8.0.0",
7676
"del-cli": "^6.0.0",
77-
"eslint": "^9.19.0",
78-
"eslint-config-prettier": "^10.0.1",
77+
"eslint": "^9.24.0",
78+
"eslint-config-prettier": "^10.1.2",
7979
"fs-extra": "^11.3.0",
8080
"husky": "^9.1.7",
8181
"jest": "^29.7.0",
82-
"lint-staged": "^15.4.3",
82+
"lint-staged": "^15.5.0",
8383
"npm-run-all": "^4.1.5",
84-
"prettier": "^3.4.2",
84+
"prettier": "^3.5.3",
8585
"standard-version": "^9.5.0",
86-
"typescript": "^5.7.3",
87-
"webpack": "^5.97.1"
86+
"typescript": "^5.8.3",
87+
"webpack": "^5.99.5"
8888
},
8989
"keywords": [
9090
"eslint",

src/index.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -150,29 +150,34 @@ class ESLintWebpackPlugin {
150150
});
151151

152152
// await and interpret results
153-
compilation.hooks.additionalAssets.tapPromise(this.key, processResults);
154-
155-
async function processResults() {
156-
const { errors, warnings, generateReportAsset } = await report();
157-
158-
if (warnings && !options.failOnWarning) {
159-
// @ts-ignore
160-
compilation.warnings.push(warnings);
161-
} else if (warnings) {
162-
// @ts-ignore
163-
compilation.errors.push(warnings);
164-
}
165-
166-
if (errors && !options.failOnError) {
167-
// @ts-ignore
168-
compilation.warnings.push(errors);
169-
} else if (errors) {
170-
// @ts-ignore
171-
compilation.errors.push(errors);
172-
}
173-
174-
if (generateReportAsset) await generateReportAsset(compilation);
175-
}
153+
compilation.hooks.additionalAssets.tapAsync(
154+
this.key,
155+
async function (callback) {
156+
const { errors, warnings, generateReportAsset } = await report();
157+
158+
if (warnings) {
159+
// @ts-ignore
160+
compilation.warnings.push(warnings);
161+
}
162+
163+
if (errors) {
164+
// @ts-ignore
165+
compilation.errors.push(errors);
166+
}
167+
168+
if (generateReportAsset) {
169+
await generateReportAsset(compilation);
170+
}
171+
172+
if (warnings && options.failOnWarning) {
173+
callback(warnings);
174+
} else if (errors && options.failOnError) {
175+
callback(errors);
176+
} else {
177+
callback();
178+
}
179+
},
180+
);
176181
});
177182
}
178183

test/fail-on-error.test.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ describe('fail on error', () => {
44
it('should emits errors', async () => {
55
const compiler = pack('error', { failOnError: true });
66

7-
const stats = await compiler.runAsync();
8-
expect(stats.hasErrors()).toBe(true);
7+
await expect(compiler.runAsync()).rejects.toThrow('error');
98
});
109

1110
it('should emit warnings when disabled', async () => {
1211
const compiler = pack('error', { failOnError: false });
1312

1413
const stats = await compiler.runAsync();
15-
expect(stats.hasErrors()).toBe(false);
16-
expect(stats.hasWarnings()).toBe(true);
14+
expect(stats.hasErrors()).toBe(true);
1715
});
1816

1917
it('should correctly identifies a success', async () => {
2018
const compiler = pack('good', { failOnError: true });
2119

22-
await compiler.runAsync();
20+
const stats = await compiler.runAsync();
21+
expect(stats.hasErrors()).toBe(false);
2322
});
2423
});

test/fail-on-warning.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ describe('fail on warning', () => {
44
it('should emits errors', async () => {
55
const compiler = pack('warn', { failOnWarning: true });
66

7-
const stats = await compiler.runAsync();
8-
expect(stats.hasErrors()).toBe(true);
7+
await expect(compiler.runAsync()).rejects.toThrow('warning');
98
});
109

1110
it('should correctly identifies a success', async () => {

test/lint-dirty-modules-only.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ describe('lint dirty modules only', () => {
4141
expect(stats.hasErrors()).toBe(true);
4242
const { errors } = stats.compilation;
4343
expect(errors.length).toBe(1);
44-
const [{ message }] = errors;
45-
expect(message).toEqual(expect.stringMatching('no-unused-vars'));
44+
expect(stats.compilation.errors[0].message).toEqual(expect.stringMatching('no-unused-vars'));
4645
done();
4746
}
4847
});

test/multiple-instances.test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ describe('multiple instances', () => {
4848
},
4949
);
5050

51-
const stats = await compiler.runAsync();
52-
expect(stats.hasWarnings()).toBe(false);
53-
expect(stats.hasErrors()).toBe(true);
51+
await expect(compiler.runAsync()).rejects.toThrow();
5452
});
5553

5654
it('should fail on second instance', async () => {
@@ -73,8 +71,6 @@ describe('multiple instances', () => {
7371
},
7472
);
7573

76-
const stats = await compiler.runAsync();
77-
expect(stats.hasWarnings()).toBe(false);
78-
expect(stats.hasErrors()).toBe(true);
74+
await expect(compiler.runAsync()).rejects.toThrow();
7975
});
8076
});

test/utils/conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default (entry, pluginConf = {}, webpackConf = {}) => {
2121
ignore: false,
2222
// TODO: update tests to run both states: test.each([[{threads: false}], [{threads: true}]])('it should...', async ({threads}) => {...})
2323
threads: true,
24+
failOnError: false,
2425
...pluginConf,
2526
}),
2627
],

0 commit comments

Comments
 (0)