Skip to content

Commit a4400b2

Browse files
fix: do not store errors, errors from files not included should not be reported (#298)
1 parent def99b0 commit a4400b2

File tree

2 files changed

+3
-32
lines changed

2 files changed

+3
-32
lines changed

src/linter.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const { dirname, isAbsolute, join } = require("node:path");
22

33
const ESLintError = require("./ESLintError");
44
const { getESLint } = require("./getESLint");
5-
const { arrify } = require("./utils");
65

76
/** @typedef {import("eslint").ESLint} ESLint */
87
/** @typedef {import("eslint").ESLint.Formatter} Formatter */
@@ -17,21 +16,6 @@ const { arrify } = require("./utils");
1716
/** @typedef {(files: string | string[]) => void} Linter */
1817
/** @typedef {{ [files: string]: LintResult }} LintResultMap */
1918

20-
/** @type {WeakMap<Compiler, LintResultMap>} */
21-
const resultStorage = new WeakMap();
22-
23-
/**
24-
* @param {Compilation} compilation compilation
25-
* @returns {LintResultMap} lint result map
26-
*/
27-
function getResultStorage({ compiler }) {
28-
let storage = resultStorage.get(compiler);
29-
if (!storage) {
30-
resultStorage.set(compiler, (storage = {}));
31-
}
32-
return storage;
33-
}
34-
3519
/**
3620
* @param {Promise<LintResult[]>[]} results results
3721
* @returns {Promise<LintResult[]>} flatted results
@@ -196,8 +180,6 @@ async function linter(key, options, compilation) {
196180
/** @type {Promise<LintResult[]>[]} */
197181
const rawResults = [];
198182

199-
const crossRunResultStorage = getResultStorage(compilation);
200-
201183
try {
202184
({ eslint, lintFiles, cleanup, threads } = await getESLint(key, options));
203185
} catch (err) {
@@ -208,9 +190,6 @@ async function linter(key, options, compilation) {
208190
* @param {string | string[]} files files
209191
*/
210192
function lint(files) {
211-
for (const file of arrify(files)) {
212-
delete crossRunResultStorage[file];
213-
}
214193
rawResults.push(
215194
lintFiles(files).catch((err) => {
216195
compilation.errors.push(new ESLintError(err.message));
@@ -224,20 +203,14 @@ async function linter(key, options, compilation) {
224203
*/
225204
async function report() {
226205
// Filter out ignored files.
227-
let results = await removeIgnoredWarnings(
206+
const results = await removeIgnoredWarnings(
228207
eslint,
229208
// Get the current results, resetting the rawResults to empty
230209
await flatten(rawResults.splice(0)),
231210
);
232211

233212
await cleanup();
234213

235-
for (const result of results) {
236-
crossRunResultStorage[result.filePath] = result;
237-
}
238-
239-
results = Object.values(crossRunResultStorage);
240-
241214
// do not analyze if there are no results or eslint config
242215
if (!results || results.length < 1) {
243216
return {};

test/watch.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ describe("watch", () => {
4444
function finish(err, stats) {
4545
expect(err).toBeNull();
4646
expect(stats.hasWarnings()).toBe(false);
47-
const { errors } = stats.compilation;
48-
const [{ message }] = errors;
49-
expect(stats.hasErrors()).toBe(true);
50-
expect(message).toEqual(expect.stringMatching("prefer-const"));
47+
expect(stats.hasErrors()).toBe(false);
5148
done();
5249
}
5350

@@ -62,6 +59,7 @@ describe("watch", () => {
6259
expect(message).toEqual(expect.stringMatching("no-unused-vars"));
6360
// `prefer-const` fails here
6461
expect(message).toEqual(expect.stringMatching("prefer-const"));
62+
expect(message).toEqual(expect.stringMatching("\\(4 errors,"));
6563

6664
next = finish;
6765

0 commit comments

Comments
 (0)